1

In the chromium console I run {} === {} and I get a Syntax error, unexpected '==='.

If I however wrap this in parens, like ({} === {}) then I get false, what I'd expect.

Is an object literal, in the first position, confused with a code block or something?

vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
  • 1
    Yes, without the parentheses it's a statement, not an expression, so it tries to interpret the first pair of curly brackets as an empty code block. – Peter Olson Mar 05 '16 at 09:55
  • Seems it needs functions to be executed in console. What about chrome console or Firefox's console. – Jai Mar 05 '16 at 09:55
  • Your guess is correct. The Chromium console lets you run arbitrary statements, not just evaluate expressions. – ruakh Mar 05 '16 at 09:55

1 Answers1

3

Without a surrounding parenthesis, {} would be considered as an empty code block in javascript. = followed by a code block would be an invalid syntax. That is why you are seeing an error there.

If you wrap it inside of a parenthesis like ({} === {}), then it would be considered as an expression and it will be evaluated to false as both are referencing two different objects.

The following example may give you a clear picture about it,

{ var x = 5; console.log(x); } == 2
// will throw the same error that you are facing.
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130