JavaScript: 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. How to Run JavaScript
  2. JavaScript: How to Use Browser Console
  3. JavaScript Tutorial by Example
  4. JavaScript: Data Types
  5. JavaScript: true, false
  6. JavaScript: Operators
  7. JavaScript: Variable
  8. JavaScript: Branch Control: if then else, switch
  9. JavaScript: for while do Loop
  10. JavaScript: Array Basics
  11. JavaScript: Object Basics
  12. JavaScript: RegExp Tutorial
  13. JavaScript: Throw Try Catch Finally
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.