Book
Submodule 13.1: Introduction to ES6
Submodule 13.1: Introduction to ES6
Completion requirements
View
- Let vs Var
- Advantages of let
- Arrow functions
Arrow functions
Arrow functions
is another new feature of ES6.
They provide a way to write functions using shorter syntax. Mainly, the functions that are converted to arrow, are the anonymous functions.
What are anonymous functions
?
Anonymous are the functions that do not have a name.
The syntax of an anonymous function is:
function (parameters) {
// do something
}
The conversion of the above to an arrow function would look like:
(parameters) => {
// do something
}
Now you have your first example of an arrow function. As you can see it is more concise from the traditional way to write functions.
What is interesting, is that this can become even more concise.
If there is only one expression you can leave off the {}
(param1, param2, …, paramN) => expression
If there is only one parameter then the parenthesis are optional
singleParam => { statements }
Example
See more about Arrow functions