JavaScript SyntaxError – Identifier starts immediately after numeric literal

This JavaScript exception identifier starts immediately after numeric literal occurs if an identifier starts with a number.

Message:

SyntaxError: Unexpected identifier after numeric literal 
             (Edge)
SyntaxError: identifier starts immediately after numeric 
             literal (Firefox)
SyntaxError: Unexpected number (Chrome)

Error Type:

SyntaxError

Cause of Error: Any JavaScript identifier should start with a letter, underscore (_), or a dollar sign ($). If they start with a digit(0-9), it will cause an error.

Example 1: In this example, there is a valid identifier, So the error has not occurred.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
        // valid identifier
        var GFG = 'This is GeeksforGeeks'; 
        document.write(GFG)
    </script>
</body>
</html>

chevron_right


Output:

This is GeeksforGeeks

Example 2: In this example, there is an identifier starting with a digit(1), So the error has occurred.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
      // Invalid identifier
      var 1GFG = 'This is GeeksForGeeks'; 
      document.write(1GFG)
    </script>
</body>
</html>

chevron_right


Output(in console): 

SyntaxError: Invalid or unexpected token

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.