本文共 1078 字,大约阅读时间需要 3 分钟。
Those operators accept two values and return a boolean:
这些运算符接受两个值并返回一个布尔值:
==
checks for equality
==
检查是否相等
!=
checks for inequality
!=
检查不平等
===
checks for strict equality
===
检查严格相等
!==
checks for strict inequality
!==
检查严格的不平等
Let’s talk what we mean for strict. Without the strict check, the second operand is converted to the type of the first before making the comparison. Strict prevents this.
让我们说说“ 严格”的含义。 如果没有严格检查,则在进行比较之前,第二个操作数将转换为第一个操作数的类型。 严格防止这种情况。
Examples:
例子:
const a = truea == true //truea === true //true1 == 1 //true1 == '1' //true1 === 1 //true1 === '1' //false
You cannot check objects for equality: two objects are never equal to each other. The only case when a check might be true is if two variables reference the same object.
您无法检查对象是否相等:两个对象永远不会彼此相等。 检查可能为true的唯一情况是两个变量是否引用同一个对象。
Some peculiarities to be aware: NaN
is always different from NaN
.
需要注意的一些特殊之处: NaN
始终不同于NaN
。
NaN == NaN //false
null
and undefined
values are equal if compared in non-strict mode:
如果在非严格模式下进行比较,则null
和undefined
值相等:
null == undefined //truenull === undefined //false
翻译自:
转载地址:http://hxqgb.baihongyu.com/