I am working with an array of numbers
let nums = [02000, 02000, 02200, 02020,02002]
The problem is when I console.log(nums)
it prints out [1024,1024,1152,1040,1026]
.
Why is it changing my numbers?
I am working with an array of numbers
let nums = [02000, 02000, 02200, 02020,02002]
The problem is when I console.log(nums)
it prints out [1024,1024,1152,1040,1026]
.
Why is it changing my numbers?
In JavaScript, Numeric Literals have their own lexical grammar.
When numbers start with a leading 0
, it may be interpreted as an octal.
Note that decimal literals can start with a zero (
0
) followed by another decimal digit, but if all digits after the leading0
are smaller than 8, the number is interpreted as an octal number.