4 ms·
For those who may be baffled at the result, it comes from parseInt accepting two arguments (string & radix), and map providing three per iteration (the value, i
by franky47 4y ago
For those who may be baffled at the result, it comes from parseInt accepting two arguments (string & radix), and map providing three per iteration (the value, index and whole array).
The whole array is omitted, but the radix passed to parseInt is respectively 0, 1 and 2.
Valid radix values are 2 to 36, but somehow 0 is also accepted due to its falsiness, and defaults to base 10. Base 1 is definitely not valid so NaNs out, and 10 in base 2 (binary) is 2.
For more of those WTF moments, in JavaScript and other languages, check out "Wat" [1], another hilarious lightning talk by Gary Bernhardt.
[1] https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat