JavaScript的双等于(==)总是对称的吗? [英] Is JavaScript's double equals (==) always symmetric?
本文介绍了JavaScript的双等于(==)总是对称的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在许多情况下,JavaScript的类型强制相等运算符不可传递。例如,请参阅 JavaScript等同传递性很奇怪。
There are many cases in which JavaScript's type-coercing equality operator is not transitive. For example, see "JavaScript equality transitivity is weird."
但是,有没有 ==
不是对称的情况?也就是说, a == b
是 true
和 b == a
是 false
?
However, are there any cases in which ==
isn't symmetric? That is, where a == b
is true
and b == a
is false
?
推荐答案
在Javascript中, ==
始终对称。
In Javascript, ==
is always symmetric.
规范说:
注2:等于运算符
维护以下不变量:
NOTE 2 The equality operators maintain the following invariants:
-
A!= B
相当于!(A == B)
。 -
A == B
相当于B == A
,除了评估
的顺序A和B
。
A != B
is equivalent to!(A == B)
.A == B
is equivalent toB == A
, except in the order of evaluation ofA and B
.
这篇关于JavaScript的双等于(==)总是对称的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文