Open In App

JavaScript SyntaxError – Missing ‘:’ after property id

Improve
Improve
Like Article
Like
Save
Share
Report

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 separate 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.

Javascript




let GFG_Obj = {
    // invalid syntax
    key = 'value'
};
console.log(JSON.stringify(GFG_Obj));


Output(In console in Edge Browser):

SyntaxError: Expected ':'

Example 2: In this example, the value is missing for the object’s key, So the error has occurred.

Javascript




// invalid syntax
let GFG_Obj = { key; };
console.log(JSON.stringify(GFG_Obj));


Output(In console in Edge Browser):

SyntaxError: Expected ':'

Last Updated : 22 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads