1

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

  • 1
    Possible 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 Answers2

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 leading 0o (or 0O) indicates it is in octal. Octal integers can include only the digits 0-7.

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
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!