-1

Javascript leading 0 on integers getting wrong value on console.log. Why I am getting like this ?

Code:

console.log(456);
console.log(0456);

Output:

456
302
HardikT
  • 715
  • 1
  • 7
  • 22
Şivā SankĂr
  • 1,856
  • 1
  • 16
  • 32

1 Answers1

2

Because JS "translates" 0456 as an octal value, since it has a trailing zero and all its digits < 8.

Andrea
  • 5,893
  • 1
  • 29
  • 53