14

On my free time, I was just playing with js console, I got an unexpected error:

js> [] == {}
false

js> {} == []
typein:5: SyntaxError: syntax error:

I tried with ===:

js> [] === {}
false
js> {} === []
typein:9: SyntaxError: syntax error:

Am thinking wrong here?

I tested this with Firefox, Chrome and jscore.

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
Renjith Thankachan
  • 4,178
  • 1
  • 30
  • 47

1 Answers1

25

That's because in the second case, {} is interpreted as a code block, rather than an object.

If you try ({}) == [] it works just fine.

js> ({}) == []
false
js> ({}) === []
false
JCOC611
  • 19,111
  • 14
  • 69
  • 90