+ 12

What is difference between Arrow function and function?

I know the the syntax is differ from function but why we use arrow functions?

16th May 2020, 12:52 PM
Shahghasi Adil
Shahghasi Adil - avatar
3 ответов
+ 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 };
16th May 2020, 1:21 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 3
it is more succinct, that's why it is paired with other ES6 feature such as Array methods forEach, map, reduce, etc.
16th May 2020, 12:55 PM
Gordon
Gordon - avatar
10th Aug 2020, 7:46 PM
Zachiah sawyer
Zachiah sawyer - avatar