PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 10, 2022

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

 August 10, 2022     decimal, javascript, language-specifications     No comments   

Issue

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.



Answered By - Sascha
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing