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