JavaScript中==和===之间的区别 [英] Difference between == and === in JavaScript

查看:221
本文介绍了JavaScript中==和===之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Javascript === vs ==:哪个“相等”我使用的运营商?

之间有什么区别? JavaScript中的== === ?我还看过!= !== 运算符。还有更多这样的经营者吗?

What is the difference between == and === in JavaScript? I have also seen != and !== operators. Are there more such operators?

推荐答案

=== !== 是严格的比较运算符:

=== and !== are strict comparison operators:


JavaScript既有严格也有
类型转换相等比较。
对于 strict 相等,
比较的对象必须具有相同的类型并且:

JavaScript has both strict and type-converting equality comparison. For strict equality the objects being compared must have the same type and:


  • 两个字符串在相应位置具有相同的
    字符序列,相同长度和相同的
    字符时严格相等。

  • 两个数字在数值上相等时严格相等(具有相同数值的
    )。 NaN 不是
    等于任何东西,包括 NaN
    正负零彼此等于

  • 如果两个布尔操作数均为真,或者两个布尔操作数均为假,则两个布尔操作数严格相等。

  • 如果两个对象引用相同的对象,则两个对象严格相等。

  • Null 未定义的类型是 == (但不是 === )。 [即( Null ==未定义)是 true 但是( Null ===未定义 false ]

  • Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
  • Two numbers are strictly equal when they are numerically equal (have the same number value). NaN is not equal to anything, including NaN. Positive and negative zeros are equal to one another.
  • Two Boolean operands are strictly equal if both are true or both are false.
  • Two objects are strictly equal if they refer to the same Object.
  • Null and Undefined types are == (but not ===). [I.e. (Null==Undefined) is true but (Null===Undefined) is false]

比较运营商 - MDC

这篇关于JavaScript中==和===之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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