Callback using arrow function
suggest changeAn arrow function can make a short callback shorter.
() => {}
To print every element of [1, 2, 3, 4, 5] with a function expression:
[1, 2, 3, 4, 5].forEach(function (x) {
console.log(x);
});
The arrow form is:
[1, 2, 3, 4, 5].forEach(x => console.log(x));
function (x) { console.log(x); } and x => console.log(x) do the same work here. They are not the same if the callback uses this, arguments, or new.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents