4 ms·
" ['1', '7', '11'].map(parseInt); For what you would expect the output to be: [1, 7, 11] However, things get a bit off here, and the actual result is: [1,Na
by sproketboy 6y ago
"
['1', '7', '11'].map(parseInt);
For what you would expect the output to be:
[1, 7, 11]
However, things get a bit off here, and the actual result is:
[1,NaN,3]
At first, this may look up very weird, but it actually has an elegant explanation.
"
The elegant explanation is that JavaScript was taken over by psychopaths like bajcmartinez.
JavaScript is fine for button onClick code. Outside of that it's garbage.
- zdragnar 6y agoparseInt has an optional second argument. map provides two arguments. Why is this an example of psychopathic design?
- bajcmartinez 6y agoit's just something unexpected that can happen because of the way you can pass functions as callbacks. I liked this example because the result looks really weird, and it can really happen to anyone, it's a mistake you can easily make and can go unnoticed.
- tempodox 6y agoYou can criticize the language to your heart's content but calling people names makes you look really bad.
- decentralised 6y agoI think the parseInt example is more of a gotcha of point-free syntax. Normally it would be written as ['1','7','11'].map(e => parseInt(e))