Great post. Some really good examples and clear improvements made.
One to be careful with though, is your point on Don't pass arguments from one function to another. It's more verbose, but sometimes you can get nasty surprises with functions taking more arguments than you might think!
For example:
['1','7','11'].map(parseInt)>[1,NaN,3]
Where the more explicit passing stops this weird behaviour.
['1','7','11'].map(n=>parseInt(n))>[1,7,11]
This happens because map passes the index of the array you're operating on to parseInt as well as the number, and this totally changes the behaviour.
Great post. Some really good examples and clear improvements made.
One to be careful with though, is your point on
Don't pass arguments from one function to another
. It's more verbose, but sometimes you can get nasty surprises with functions taking more arguments than you might think!For example:
Where the more explicit passing stops this weird behaviour.
This happens because map passes the index of the array you're operating on to parseInt as well as the number, and this totally changes the behaviour.
Thanks, I’m glad you liked it :)
That’s a great point, thanks for pointing it out!