-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
  • 735
  • 1
  • 8
  • 24
Şivā SankĂr
  • 1,966
  • 1
  • 18
  • 34

1 Answers1

2

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

Andrea
  • 6,032
  • 2
  • 28
  • 55