-
• #2
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
parseInt("010", 10)
.I'll add a bug for this anyway, to remove that code and make it sane again.
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