Why does console.log(0123);
log the integer . 83
? I'm not sure why it would and don't really have an idea either.
Asked
Active
Viewed 344 times
1

Alexander John
- 139
- 6
-
1Possible duplicate of [Why does JavaScript output 16384 instead of 040000?](http://stackoverflow.com/questions/21036122/why-does-javascript-output-16384-instead-of-040000) – default locale Oct 11 '16 at 06:30
-
Possible duplicate of [Prefix zero changes output in number addition](http://stackoverflow.com/questions/9139648/prefix-zero-changes-output-in-number-addition) – cske Oct 11 '16 at 06:47
2 Answers
4
Because it's interpreted as an octal number, and octal 123 corresponds to decimal 83 (64 + 16 + 3).
From MDN:
Leading
0
(zero) on an integer literal, or leading0o
(or0O
) indicates it is in octal. Octal integers can include only the digits 0-7.

Robby Cornelissen
- 91,784
- 22
- 134
- 156
-
-
-
Note that in strict mode you'll get `SyntaxError: Octal literals are not allowed in strict mode.` for the literal `0123` but *not* for `0o123`. – nnnnnn Oct 11 '16 at 05:19
0
Because the leading 0 (zero) 0o or 0O on an integer indicates an octal number!!
Octal numbering system is used less nowadays and has almost disappeared as a digital base number system. Hexadecimal numbering system is so popular now!

Faisal Ahmed
- 21
- 7