+ 12
What is difference between Arrow function and function?
I know the the syntax is differ from function but why we use arrow functions?
3 odpowiedzi
+ 4
the biggest difference is that compared to a normal function, an arrow function does not have the following in its context:
1) 'this' keyword
2) arguments
3) 'super' keyword
4) new.target
also the 'return' keyword can be omitted when not using curly braces:
const sum = (a,b) => a + b;
instead of:
const sum = (a,b) => { return a + b };
+ 3
it is more succinct, that's why it is paired with other ES6 feature such as Array methods forEach, map, reduce, etc.
+ 1