ES6 Arrow Functions

In ES6, a function can be written in a new way using =>.

This is useful in writing nameless handler functions. It has the same context as the code from which it is called.

In the following ES5 example this.factor is undefined in the map handler function because of context change in function


But in ES6, a function with the same context can be defined using =>

To invoke it immediately, enclose it in ()() as shown below

Curly braces can be used if there are more statements

Share