Related Articles

Related Articles

JavaScript SyntaxError – Missing ‘:’ after property id
  • Last Updated : 24 Jul, 2020

This JavaScript exception missing : after property id occurs if objects are declared using the object’s initialization syntax.

Message:

SyntaxError: Expected ':' (Edge)
SyntaxError: missing : after property id (Firefox)

Error Type:

SyntaxError

Cause of Error: Somewhere in the code, Objects are created with object initializer syntax and colon (:) is used to separates keys and values for the object’s properties, Which is not used so.

Example 1: In this example, the “=” is used in place of “:”, 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>
        var GFG_Obj = { 
            // invalid syntax
            key = 'value' 
        };
        document.write(JSON.stringify(GFG_Obj));
    </script>
</body>
</html>

chevron_right


Output(In console in Edge Browser):

SyntaxError: Expected ':'

Example 2: In this example, the value is missing for object’s key, 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 syntax
      var GFG_Obj = { key; };  
      document.write(JSON.stringify(GFG_Obj));
    </script>
</body>
</html>

chevron_right


Output(In console in Edge Browser):

SyntaxError: Expected ':'

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :