1

Possible Duplicate:
Workarounds for JavaScript parseInt octal bug

Here's a jsfiddle that shows the behavior:

Pretty simple question, any ideas?

Code is just:

parseInt(013)
Community
  • 1
  • 1
Jake
  • 4,014
  • 8
  • 36
  • 54

3 Answers3

12

Because if your number is starting with '0', then it's considered as octal, thus

'013' = 1 * 8 + 3 = 11
Orabîg
  • 11,718
  • 6
  • 38
  • 58
10

parseInt() expects a string. You have provided an octal, 013.

Use:

parseInt('013', 10)

Note: I would also encourage passing radix, for clarity.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
2

The number 013 is being interpreted as an octal. It has nothing to do with parseInt; in fact, var a = 013; will have a be 11.

Ivan
  • 10,052
  • 12
  • 47
  • 78