June 2018
Intermediate to advanced
348 pages
8h 19m
English
You need to iterate over the elements of an array; normally, you would write something like this:
var data = ['Ronaldo', 'Messi', 'Maradona'];data.forEach(function (elem) { console.log(elem)});
With the arrow functions, you can refactor your code and write something as follows:
var data = ['Ronaldo', 'Messi', 'Maradona'];data.forEach(elem => { console.log(elem);});
The arrow (=>) operator defines a function in one line, making our code readable and ordered. First, you need to declare the inputs; the arrow will send these params to the function body defined by the operator:
// We could transform thislet sum = function(num) { return num + num;};// Into just thislet sum = (num) => num + num;
Read now
Unlock full access