JavaScript相等运算符

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 = true

a == true //true
a === true //true

1 == 1 //true
1 == '1' //true
1 === 1 //true
1 === '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:

如果在非严格模式下进行比较,则nullundefined值相等:

null == undefined //true
null === undefined //false

翻译自: https://flaviocopes.com/javascript-equality-operators/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值