Arrow Functions
Arrow functions allows a short syntax for writing function expressions.
You don't need the function keyword, the return keyword, and the curly brackets.
Example
// ES5var x = function(x, y) {
return x * y;
}
// ES6const x = (x, y) => x * y;
Arrow functions do not have their own this. They are not well suited for defining object methods.
Arrow functions must be defined before they are used. Using const is safer than using var, because a function expression is a constant value.
You can only omit the return keyword and the curly brackets if the function is a single statement.
It might be a good habit to keep them:
// ES5var x = function(x, y) {
return x * y;
}
// ES6const x = (x, y) => x * y;
Example
const x = (x, y) => { return x * y };
const x = (x, y) => { return x * y };