JavaScript SyntaxError – Missing ‘:’ after property id
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
<!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> |
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
<!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> |
Output(In console in Edge Browser):
SyntaxError: Expected ':'


