forEach(e => { code })
and forEach(function(e){ other code })
can perform the same task, however they are not equivalent per se.
The first one uses the new arrow function introduced in ECMA6. Arrow functions capture the outer scope’s this
(i.e. when you use this
it refers to the the scope of the function containing it.) Regular functions however have their own this
. The fact that arrow functions do not have their own this
is actually one of the reasons why it was introduced. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
The second difference is that you cannot bind an arrow function.
Another difference arises in strict mode. Given that this comes from the surrounding lexical context, strict mode rules with regard to this are ignored by arrow functions.
So while you can basically perform the same task using either of them, one might be more convenient than the other depending on your case.