Why does the radix for JavaScript’s parseInt default to 8?

It only “defaults” to 8 if the input string starts with 0. This is an unfortunate carryover from C and C++.

You can use Number('0123') instead, or, as you said in the question, parseInt('0123', 10).

How do I work around JavaScript’s parseInt octal behavior?


Can you tell me more about this carryover?


Note: ECMAScript strict mode removes octal syntax.

Leave a Comment