-1

const arr = [0123, 1456];
console.log(arr);

The result is [ 83, 1456 ], but I think it should be [0123, 1456].

The first element is wrong. I don't know why.

Andy
  • 61,948
  • 13
  • 68
  • 95
  • In javascript a number beginning with `0` followed by a digit lower than `8` or `9` is interpreted as an octal number therefore `0123` (octal) becomes 3*8^0 + 2*8^1 + 1*8^2 = 3 + 16 + 64 = `83` (decimal) – secan Aug 04 '21 at 09:56

1 Answers1

-2

Numbers starting with zero are octal integers. You might want to use 123 as your first member of the array.

Dropout
  • 13,653
  • 10
  • 56
  • 109