3 ms·
It's due to parseInt having an optional second parameter, the radix, and map passing the index as the second paramater, hence: xs = [ parseInt('10', 0),
by TazeTSchnitzel 13y ago
It's due to parseInt having an optional second parameter, the radix, and map passing the index as the second paramater, hence:
xs = [
parseInt('10', 0),
parseInt('10', 1),
parseInt('10', 2)
]
- jisaacks 13y agoAnd since 0 is falsy we get 10 for base 0.
- TazeTSchnitzel 13y agoWhich is odd. I wonder why they checked for falsiness and not the argument being undefined.
- kevincennis 13y agoIt's not exactly checking for falsy values. Although all falsy values will lead to a radix of 10 being applied. parseInt internally uses the ToInt32 abstract operation on the radix parameter. Once it has that value, it explicitly looks to see if the value is 0. If it is, it uses a radix of 10. https://people.mozilla.org/~jorendorff/es6-draft.html#sec-parseint-string-radix https://people.mozilla.org/~jorendorff/es6-draft.html#sec-pa... Edit: I hope that doesn't come off as pedantic. My point wasn't to disagree as much as it was to just add some further explanation.
- meowface 13y agoThis is HN, there's no such thing as being pedantic. :)
- Thirdegree 13y agoOr rather, there is but it's thoroughly welcome.
- mturmon 13y agoAlthough keep in mind that excessive pedantry is frowned upon.
- octatone2 13y agoIt's not optional if you lint your code :)
- davidkassa 13y agoThank you. I read many comments to find an explanation.