0

I have this code:

console.log(066); // 54

Why does it log 54, not 66?

Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111
Huy
  • 11
  • 2

2 Answers2

1

In JavaScript, numeric literals that begin with a 0 are treated as octal.

From the MDN docs:

Octal number syntax uses a leading zero. If the digits after the 0 are outside the range 0 through 7, the number will be interpreted as a decimal number.

jmar777
  • 36,974
  • 11
  • 63
  • 64
0

Because add a prefix 0 will make the number to be considered of base 8(octal), as way 0x will make the following number to be of base 16(hexa)

Arun P Johny
  • 376,738
  • 64
  • 519
  • 520