top | item 36450806

(no title)

vortico | 2 years ago

The reason is surprising but perfectly valid once you remember the spec of map() and parseInt(). Love JS WTFs.

discuss

order

bluepod4|2 years ago

Yep. I actually recall someone on the team running into a similar issue during the workday.

triyambakam|2 years ago

I wouldn't even call it a JS WTF. If you use a tool wrong, why be surprised about wrong results?

dragonwriter|2 years ago

Its a footgun that results from JS’s loose typing of functions, allowing them both to be called with discarded arguments and to be flexible in the number of arguments they accept.

While each of those flexibilities can be useful, they interact in annoying ways. The fact that map passes three arguments but is often used as if it was passing one, and that parseInt accepts two arguments but is often used as if it accepted one makes it very easy to make this mistake.

vikingerik|2 years ago

If everybody uses a tool wrong, the problem isn't with everybody, it's with the tool.

paulddraper|2 years ago

It's unexpected.

No other language does this.

qayxc|2 years ago

How on Earth is that a WTF? Ignoring the specs will lead to unexpected results regardless of the language or API used.