November 2017
Intermediate to advanced
386 pages
9h 22m
English
Arrow functions are just a shorter, more succinct way of creating an (unnamed) function. Arrow functions can be used almost everywhere a classical function can be used, except that they cannot be used as constructors. The syntax is either (parameter, anotherparameter, ...etc) => { statements } or (parameter, anotherparameter, ...etc) => expression. The first one allows you to write as much code as you want; the second is short for { return expression }. We could rewrite our earlier Ajax example as:
$.get("some/url", data, (result, status) => { // check status, and do something // with the result});
A new version of the factorial code could be:
const fact2 = n => { if (n === 0) { return 1; } else { return n * fact2(n - 1); ...