且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么比较{}和[]会显示错误?

更新时间:2023-09-21 22:48:40

这是因为在第二种情况下,{}被解释为代码块,而不是对象.

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