Traditional Culture Encyclopedia - Traditional stories - Syntax of ES6 arrow function and when not to use it.

Syntax of ES6 arrow function and when not to use it.

ES5:

Function f (a, b) {

Return a+b;

}

-& gt; ES6

Let f = (a, b) = > a + b

ES5:

Function f (a, b) {

Console.log ('Hello ES6.' );

Return a+b;

}

-& gt; ES6

Let f = (a, b) = > {

Console.log ('Hello ES6.' );

Return a+b;

}

If you write a function in a code block, if there is a return, you need to write your own return.