https://github.com/Chalarangelo/30-seconds-of-code#current-u...
> Use window.location.href to get current URL.
var currentUrl = _ => window.location.href;https://github.com/Chalarangelo/30-seconds-of-code#current-u...
> Use window.location.href to get current URL.
var currentUrl = _ => window.location.href; () => window.location.href var currentUrl = function () { return window.location.href; }Note that this is a convention, not a requirement for the syntax (like in some other languages).
I've spent at least a few mins troubleshooting why `_.map` (from `lodash` npm module) didn't work inside of a fat function while fixing another developer's defect.
If you use `_` as a valid const/variable identifier anywhere in your codebase, I would recommend you ditch `_ => alert(1)` for something more obscure like `ø => alert(1)`
var currentUrl = function(_) {
return window.location.href;
}
the underscore is used so they don't have to type `() =>` insteadThis was a new syntax added to the language spec to reduce the amount of boilerplate required for common tasks.
Also, the "fat arrow function" handles "this" different inside of the function, so it can serve a slightly different function and in many event-handling cases it can be even more terse than traditional JS functions.