1

It might be a dumb question, today I was playing with Firebug,

I typed:

var test = 100011;
console.log(test);

I get out put as 100011 which is correct

But when I type the following code:

var test = 0100011;
console.log(test);

I get 4097

Why am I getting 4097?

Ajean
  • 5,528
  • 14
  • 46
  • 69
Dilip Rajkumar
  • 7,006
  • 6
  • 60
  • 76

1 Answers1

2

A preceding 0 causes the number to be interpreted in octal.

A preceding 0x causes the number to be interpreted in hexadecimal.

j-da
  • 188
  • 10
  • 1
    You may want to look in to using strict mode. It flags octal numbers as an error. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode – River Nov 14 '14 at 13:41