In today's edition of "oh my god everything is so freaking interconnected", I learned a W I L D thing about JavaScript's parseInt function:
-
-
The part of the former that's not entirely sensible is that it seems to lack any way to say the entire input wasn't consumed/valid.
-
As opposed to strtol which exposes this part of the outcome via *endptr.
End of conversation
New conversation -
-
-
I guess that parseInt is defined first doing arg0.toString()?
-
Almost. It calls ToString(arg0). (Sect. 15.1.2.2 of 3rd edition of ECMA-262 from 1999, I don't know if this changed in newer editions.)pic.twitter.com/ugcoU1zMzk
End of conversation
New conversation -
-
-
Upon some thinking, I saw why it behaves that way: Consider 012...89abc...lmn. Counting from 0, 'n' is 23rd #. So it parsed 'null', and >>
-
it stopped at 'u' since that is outside the range (base 24), so it converted 'n' into number 23. There! But it does confuse us humans!

- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.