Callback using arrow function

suggest change

An 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents