且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JavaScript中==和===之间的区别

更新时间:2023-12-04 11:27:34

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

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