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

This is a common Javascript gotcha with a simple solution:

Just specify the base, or ‘radix’, like so:

parseInt('08',10); // 8

You could also use Number:

Number('08'); // 8

Leave a Comment