JavaScript的双等于(==)总是对称的吗? [英] Is JavaScript's double equals (==) always symmetric?

查看:127
本文介绍了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 to B == A, except in the order of evaluation of A and B.

这篇关于JavaScript的双等于(==)总是对称的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆