7

Possible Duplicate:
JavaScript function parseInt() doesn't parse numbers with leading 0 correctly

Strange issues when parsing in JS occur.

parseInt("08")
//The result is: 0

parseInt("07")
//The result is: 7

Why is this happening?

Community
  • 1
  • 1
petko_stankoski
  • 10,459
  • 41
  • 127
  • 231

1 Answers1

11

Because of the 0 prefix. It tells Javascript the number is Octal, in base-8. 8 isn't a legal octal digit.

Use parseInt("8") instead, or as @Gumbo so correctly pointed out - parseInt("08", 10)

zmbq
  • 38,013
  • 14
  • 101
  • 171