问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/42185021/why-does-comparing-and-show-an-error