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
  • 44,719
  • 11
  • 118
  • 156
Renjith Thankachan
  • 3,896
  • 1
  • 25
  • 44

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
  • 18,283
  • 14
  • 65
  • 89