SyntaxStudy
Sign Up
JavaScript Beginner 1 min read

Arrow Functions

Arrow Functions

Concise ES6 syntax. Single-param: no parens. Single-expression: no braces/return.

Key Difference

Arrow functions do not have their own this — they inherit it from parent scope.

Example
const double = n => n*2;
const add = (a,b) => a+b;
const greet = name => {
  return `Hi ${name}!`;
};

// Great in array methods:
[1,2,3].map(n=>n*2);    // [2,4,6]
[1,2,3].filter(n=>n>1); // [2,3]