🔰arrow function

(ES6) a new form of function expression.

JSvaluefunction ⟩ arrow function

⭐️ ES6 (2015):a new form of function expression.

a => expression       // one statement: {...} optional
(a, b) => expression  // multiple params: (...) required
a => { statement1; statement2; } // multiple statements: {...} required

when the { ... } are omitted, a return value is sent out without using return.

doesn’t have own bindings to this, arguments or super.

⭐️ arrow function as method❗️ (❗️use with caution❗️)

normally, you don't use arrow functions as methods, but if you have:

  • an object A that has a method returning a new object B,

  • object B has its own methods,

  • you don't want this in these methods to refer to B but refer to A instead,

then using arrow functions as methods is an option.

👉 see example: Sequence

  • aren't suitable for call, apply and bind methods, which generally rely on establishing a scope.

  • don't have access to new.target keyword.

  • can’t be used as constructors. (can’t be called with new)

  • can’t use yield, within its body.

deplicate parameters Early Error rule (🚧) is always applied to arrow function definition even if 'strict mode' (🚧) is not defined explicitly.

Last updated