javascriptdecimallanguage-specifications

Why does a decimal number with a 0 before it produce a SyntaxError?


I was writing some Javascript when I accidentally typed 04.5 instead of 40.5. When I ran the code, it produced a SyntaxError that read Uncaught SyntaxError: Unexpected number. I tested this in Chrome, Safari, Firefox, and NodeJS, and they all produced the same error. I looked through the Javascript specifications, but I couldn't find anything on it. What is Javascript interpreting a decimal number with a 0 before it as?

04.5 // Uncaught SyntaxError: Unexpected number


Solution

  • With a leading zero it's interpreted as octal. But it seems that octals are not liked with decimal places.