0

I have this code:

console.log(066); // 54

Why does it log 54, not 66?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
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
  • 38,796
  • 11
  • 66
  • 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
  • 384,651
  • 66
  • 527
  • 531