Arrow functions provide a concise syntax for writing function expressions.
You can omit the function keyword, the return keyword, and the curly braces.
| // ES5 var x = function(x, y) { return x * y; } // ES6 const x = (x, y) => x * y; |
Arrow functions don’t have their own this, making them unsuitable for object methods. They are not hoisted and must be defined before use. Using const is safer than var as it treats the function expression as a constant. If the function has a single statement, you can omit the return keyword and curly braces, though it’s often clearer to keep them.
| const x = (x, y) => { return x * y }; |
| Arrow functions are not supported in Internet Explorer 11 or earlier versions. |