Concise Modern Style

Arrow functions are a shorter way to write functions, introduced in ES6.

Syntax

let sum = (a, b) => a + b;
/* This is the short version of:
let sum = function(a, b) {
  return a + b;
}; */
  • If there is only one parameter, parentheses can be omitted: n => n * 2.
  • If there are no parameters, parentheses are required: () => alert("Hi").
Tip

Arrow functions are perfect for one-line actions and passing as arguments (callbacks).