I have heard someone saying that Javascript arrow functions can be used to "solve some scope related problems".
So far I've known that the main advantage of JavaScript arrow functions is by saving syntax or allow implicit behavior.
1) Shorter ("sugar") syntax example:
()=>{...}
let myFunction = ()=>{...}
Are shorter than:
function() {...}
function myFunction() {...}
2) Implicit behavior as in this reduce()
example:
let prices = [1, 2, 3, 4, 5];
let result = prices.reduce( (x,y)=> x+y );
// Reduce data from x to y (reduce needs return, which is included implicitly). Result will be 15 (1+2+3+4+5 are reduced to 15, in this case).
I fail to associate these and other examples with scope. I know that there was a problem with scope in which a variable declared inside a function with var
couldn't be inherited to a sub function and this problem was solved when const
and let
where introduced (they allow such inheritance).
So what are the main scope problems arrow functions come to solve beside of suggesting sugar syntax and some implicit behaviors?