Arrow functions provide a concise syntax for writing function expressions.
You no longer need the function keyword, the return keyword, or curly brackets for single-expression functions.
| // ES5 var x = function(x, y) { return x * y; } // ES6 const x = (x, y) => x * y; |
Arrow functions lack their own this, aren’t hoisted, and work best when declared with const. While braces and return can be skipped for single statements, including them adds clarity.
| const x = (x, y) => { return x * y }; |