radix for parseInt ? #417
Replies: 1 comment
-
Posted at 2015-05-26 by @gfwilliams I just looked this up, and: https://whereswalden.com/2011/02/26/the-proper-way-to-call-parseint-tldr-parseintstr-radix/ Note that it's from 2011 and it's explaining that some browsers do one thing and some do another. I just checked back and I had a bug report in 2012 because it didn't do this, and I 'fixed' it. I probably should have checked the spec and refused, because in ES5 (not before) it shouldn't parse it as Octal. So yeah, if you want to write JS code that works even on ES3 web browsers and Espruino, explicitly specify the radix with I'll add a bug for this anyway, to remove that code and make it sane again. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-05-26 by JumJum
In my browser, default radix for parseInt is 10, in Espruino its 8 if there are leading zeros.
parseInt("10") returns 10
parseInt("010") returns 8
Beta Was this translation helpful? Give feedback.
All reactions