Re:The Birth and Death of JavaScript [video]
by TazeTSchnitzel on Thursday April 17, 2014 @05:04PM
(#7606333)
It's due to parseInt having an optional second parameter, the radix, and map passing the index as the second paramater, hence:
[ Parent
| on HN ]
Re:The Birth and Death of JavaScript [video]
by jisaacks on Thursday April 17, 2014 @05:09PM
(#7606380)
And since 0 is falsy we get 10 for base 0.
Re:The Birth and Death of JavaScript [video]
by kevincennis on Thursday April 17, 2014 @08:28PM
(#7607354)
It'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-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.
Re:The Birth and Death of JavaScript [video]
by meowface on Friday April 18, 2014 @06:36AM
(#7608691)
This is HN, there's no such thing as being pedantic. :)
Re:The Birth and Death of JavaScript [video]
by mturmon on Saturday April 19, 2014 @01:01AM
(#7612638)
Although keep in mind that excessive pedantry is frowned upon.
Re:The Birth and Death of JavaScript [video]
by Thirdegree on Saturday April 19, 2014 @12:55AM
(#7612627)
Or rather, there is but it's thoroughly welcome.
Re:The Birth and Death of JavaScript [video]
by TazeTSchnitzel on Thursday April 17, 2014 @05:12PM
(#7606401)
Which is odd. I wonder why they checked for falsiness and not the argument being undefined.
Re:The Birth and Death of JavaScript [video]
by davidkassa on Friday April 18, 2014 @10:46AM
(#7609329)
Thank you. I read many comments to find an explanation.