Possible Duplicate:
Workarounds for JavaScript parseInt octal bug
Surprisingly it returns 0. Why? and what’s the (proper) solution to get correct results?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a radix:
Some JavaScript implementations add a third numeral system to the two defined by the standard (decimal, the default; and hex, prefixed with
0x): Octal, prefixed with0. This is non-standard but acknowledged as common in the latest spec.Since
8is not a valid octal digit,parseIntstops there, returning the value0.By explicitly using a radix, you tell
parseIntnot to try to figure out what numeral system is being used but instead to use the one you specify. Your instinct when typingparseIntshould always be to specify the radix; not doing so leaves you open to oddities.