为什么0 === {}可以,但是{} === 0会引发错误? [英] Why is 0 === {} okay, but {} === 0 throws an error?
本文介绍了为什么0 === {}可以,但是{} === 0会引发错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在浏览器控制台中添加了以下内容:
I put the following into the browser console:
0 === {} // false
{} === 0 // SyntaxError: expected expression, got '==='
这是为什么?
推荐答案
{} === 0
此处 {}
是不是对象文字的语句块.
{} === 0
here {}
is block statement not object literal.
但是如果您确实说 var a = {} === 0
会起作用
But if you do say var a = {} === 0
it would work
var a = {} === 0
console.log(a);
这篇关于为什么0 === {}可以,但是{} === 0会引发错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文