JS: Browser JS Console Object Syntax Error

By Xah Lee. Date: .

Uncaught SyntaxError: Unexpected token {

browser console js object syntax error 20161027
Common error when using brower console to evaluate a JavaScript object literal expression. Google Chrome Browser, 2016-10-27.

One common error when using console is that when you type this:

{"x":3, "y":4};

and you get an error:

Uncaught SyntaxError: Unexpected token

It's a quirk in the JavaScript language. It thinks you are using a code block, not object.

solution is to wrap the object by parenthesis, like this:

({"x":3, "y":4})

In Google Chrome, omitting the semicolon also works. (but not in Firefox as of )

{"x":3, "y":4}
browser console js object syntax error ff 20161027
Common Error when using brower to evaluate a JavaScript object. Firefox Browser, 2016-10-27.

JavaScript Basics

  1. JavaScript Basics
  2. true, false
  3. Operators
  4. Branch Control
  5. Loop
  6. Array Basics
  7. Object Basics
  8. RegExp Basics
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog