JavaScript:为什么输出是假的?[复制]

JavaScript: Why is the output false? [duplicate]

提问人:Nice18 提问时间:11/22/2021 最后编辑:Nice18 更新时间:6/16/2022 访问量:139

问:

console.log(`${window === this} (window === this)`)
console.log(`${window === self} (window === self)`)
console.log(`${this === self} (this === self)`)

console.log(`${window === this === self} (window === this === self)`)

为什么在 JavaScript 中是 falsewindow === self === this

JavaScript 对象 输出 相等

评论

2赞 derpirscher 11/22/2021
因为等价于 ,因此如果不是布尔值,这显然是错误的a === b === c(a === b) === ctrue === cc

答:

1赞 Spectric 11/22/2021 #1

因为不等于 .truethis

此表达式:

window === self === this

相当于:

true === this

这是错误的,因为不是布尔值。this

0赞 Olian04 11/22/2021 #2

因为你不能在 javascript 中以这种方式链接相等运算符。 实际上与:首先计算括号的地方相同。换言之,等于 的计算结果为 。window === this === self(window === this) === selfwindow === this === selftrue === selffalse