Lesson 11 / 38

Arrow Functions

Concise syntax, and how `this` behaves differently.

Concise syntax

A single expression can skip both return and the braces.

const square = (n) => n * n;
const add = (a, b) => { return a + b; };
console.log(square(5));  // 25

No own this

Arrow functions don't bind their own this — they inherit it from the surrounding scope, which fixes a common callback bug.

When not to use them

Avoid arrow functions as object methods when you need this to refer to the object — use a regular method instead.