关于比较运算符:javascript中的==和===之间的差异

Difference between == and === in JavaScript

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
Javascript === vs == : Does it matter which “equal” operator I use?

在javascript中,=====有什么区别?我也见过!=!==的操作员。有更多这样的运营商吗?


请看:http://longgoldenears.blogspot.com/2007/09/triple-equals-in-javascript.html

这3个等号表示"没有类型强制的平等"。使用"三重等于"时,类型中的值也必须相等。

1
2
3
4
5
6
7
8
0 == false   // true
0 === false  // false, because they are of a different type
1 =="1"     // true, automatic type conversion for value only
1 ==="1"    // false, because they are of a different type
null == undefined // true
null === undefined // false
'0' == false // true
'0' === false // false


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

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

  • 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