June 2016
Intermediate to advanced
910 pages
18h 59m
English
ES6 provides a new way to create functions using the => operator. These functions are called as arrow functions. This new method has a shorter syntax, and the arrow functions are the anonymous functions.
Here is an example that shows how to create an arrow function:
let circleArea = (pi, r) => {
let area = pi * r * r;
return area;
}
let result = circleArea(3.14, 3);
console.log(result); //Output "28.26"Here, circleArea is a variable, referencing to the anonymous arrow function. The previous code is similar to the next code in ES5:
Var circleArea = function(pi, r) {
var area = pi * r * r;
return area;
}
var result = circleArea(3.14, 3);
console.log(result); //Output "28.26"If an arrow function contains just one statement, then ...
Read now
Unlock full access