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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值