JS: Object Literal Expression SyntaxError: Unexpected token colon

By Xah Lee. Date: . Last updated: .

Syntaxerror: unexpected token :

if you type

{ a: 7, b: 8 }

you may get a syntax error about unexpected token colon.

SyntaxError: Unexpected token :
js obj syntax error 2026-01-27 16863
js obj syntax error 2026-01-27 16863

That is because JavaScript confused object literal with statement block syntax. Due to bad design of JavaScript.

Solution

solution is to add a paren:

({ a: 7, b: 8 })