[Weird Javascript Error] Leading Zero on Integer Variable Become Octal on Old Browser

Ive met a very weird error, that somehow never occurs to me on my browser. I found this error only happen on old mozilla browsers, and only happen on javascript’s parseInt method. Here is a simple example,


When im running it on my browser (Mozilla version 34), this is what happen,

But when running on old browsers (Mozilla version 3.6), this is what happen,

I finally found out that that on old browsers, leading zeros are treated as octal values instead of plain integers. So this is my workaround,


I removed the leading zero before parsing it into int.

Hope it can help others 🙂



about 6 years ago

Or you could just use the parseInt(String s, int radix) overload and set the radix to 10.



about 6 years ago

hi egincheff, thank you for your workaround :)

Leave a Comment

Leave a Reply to egincheff or Cancel Reply

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked