zaagan
7/2/2019 - 12:05 PM

JavaScript Arrow Function Statement Bodies

JavaScript Arrow Function Statement Bodies

var evens = [2,4,6,8,10,12,14,16,18];

/* ES 5 */
let totalEs5 = 0;
evens.forEach(function(item) { totalEs5 += item;  });
// Output : 90

/*  ES6 - Arrow function  */
let totalEs6 = 0;
evens.forEach(item => { totalEs6 +=  item;  });
console.log(totalEs6);
// Output : 90