7 ms·
And since 0 is falsy we get 10 for base 0.
by jisaacks 12y ago
And since 0 is falsy we get 10 for base 0.
- TazeTSchnitzel 12y agoWhich is odd. I wonder why they checked for falsiness and not the argument being undefined.
- kevincennis 12y 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 12y agoThis is HN, there's no such thing as being pedantic. :)
- Thirdegree 12y agoOr rather, there is but it's thoroughly welcome.
- mturmon 12y agoAlthough keep in mind that excessive pedantry is frowned upon.