SyntaxError: missing : after property id

The JavaScript exception "missing : after property id" occurs when objects are created using the object initializer syntax. A colon (:) separates keys and values for the object's properties. Somehow, this colon is missing or misplaced.

Message

SyntaxError: Invalid shorthand property initializer (V8-based)
SyntaxError: missing : after property id (Firefox)
SyntaxError: Unexpected token '='. Expected a ':' following the property name 'x'. (Safari)
SyntaxError: Unexpected token '+'. Expected an identifier as property name. (Safari)

Error type

SyntaxError

What went wrong?

When creating objects with the object initializer syntax, a colon (:) separates keys and values for the object's properties.

Examples

Colons vs. equal signs

This code fails, as the equal sign can't be used this way in this object initializer syntax.

Correct would be to use a colon, or to use square brackets to assign a new property after the object has been created already.

Or alternatively:

Computed properties

If you create a property key from an expression, you need to use square brackets. Otherwise the property name can't be computed:

Put the expression in square brackets []:

See also