October 2018
Intermediate to advanced
590 pages
15h 5m
English
ES6 introduces arrow functions as a function shorthand, using => syntax. Arrow functions support statement block bodies as well as expression bodies. When using an expression body, the expression's result is the value that the function returns.
An arrow syntax begins with function arguments, then the arrow =>, and then the function body. Let's look at the following different variations of arrow functions. The examples are written in both ES5 syntax and ES6 arrow function syntax:
const fruits = [{name: 'apple', price: 100}, {name: 'orange', price: 80}, {name: 'banana', price: 120}];// Variation 1// When no arguments, an empty set of parentheses is requiredvar countFruits = () => fruits.length;// equivalent to ES5var countFruits ...
Read now
Unlock full access