javascript difference between == and ===

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

  • 0==false   // true
    0===false  // false, because they are of a different type
    1=="1"     // true, auto type coersion
    1==="1"    // false, because they are of a different type
  • >>> new String("aa")===new String("aa")
    false
    >>> new String("aa")==new String("aa")
    false
  • >>> "aa"=="aa"
    true
    >>> "aa"==="aa"
    true
  • >>> NaN===NaN //false

  • >>> var user1 = {name : "nerd", org: "dev"}; var user2 = {name : "nerd", org: "dev"}; console.log(user1==user2)
    false
     
       
      For furthur information, please check
  • http://stackoverflow.com/questions/1068834/object-comparison-in-javascript

你可能感兴趣的:(JavaScript)