October 2017
Intermediate to advanced
280 pages
6h 50m
English
JavaScript has first-class functions, which means that they can be passed around like any other value:
// ch4/arrow-functions/simple-reduce.ts
var result = [1, 2, 3].reduce(function (total, current) {
return total + current;
}, 0); // 6
This syntax is great; however, it is a bit too verbose. ES2015 introduced a new syntax to define anonymous functions called the arrow function syntax. Using it, we can create anonymous functions, as seen in the following examples:
// ch4/arrow-functions/arrow-functions.ts // example 1 var result = [1, 2, 3] .reduce((total, current) => total + current, 0); console.log(result); // 6 // example 2 var even = [3, 1, 56, 7].filter(el => !(el % 2)); console.log(even); // [56] // example 3 ...
Read now
Unlock full access