2 ms·
Mindblown that we built the Web on this... xs = ['10','10','10'] (3) ['10', '10', '10'] xs.map(parseInt) (3) [10, NaN, 2]
by belter 4y ago
Mindblown that we built the Web on this...
xs = ['10','10','10']
(3) ['10', '10', '10']
xs.map(parseInt)
(3) [10, NaN, 2]
- franky47 4y agoFor 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