DEV Community

Discussion on: Common JavaScript Mistakes You May be Making

Collapse
 
craigmc08 profile image
Craig McIlwrath

The second simplification is called eta-reduction, but in this case it is not valid eta-reduction because result of the expression changes.

In the original, it will log the value of each item. In the reduced form, it logs the value, index, and entire array for each item (Array.prototype.forEach actually passes 3 parameters). This is a mistake to be mindful of.

Thread Thread
 
aumayeung profile image
John Au-Yeung

Yea. That example works in JavaScript because it lets use pass in anything to a function.

It's very easy to make a mistake passing in a function like that