解决方案 »

  1.   

    if (a===b) 
    http://blog.csdn.net/wxdzxl/article/details/8502119
      

  2.   

    看了你给的链接,;里面还是没有解释undefined类型的a 与null类型的b是怎么进行比较的.
    是先将a转换成bool类型 ,b转换成bool类型之后在进行比较吗?
    但是我 用if(a==false)测试,结果还是相等.
      

  3.   


    == 不检查类型,只检查值。
    在javascript里面: null, undefined, false, '' 的值都是false
      

  4.   

    上面那个
         if(a==false)测试,结果还是相等. 
    写错了
    if(a==false) 测试结果是不相等的.
      

  5.   


    == 不检查类型,只检查值。
    在javascript里面: null, undefined, false, '' 的值都是false
    如果是 undefined的值是false的话
    那么if(a==false)测试结果该是相等的,我测试的结果不是相等的.
    但是 if(a==undefined) 结果却是相等的
      

  6.   


    == 不检查类型,只检查值。
    在javascript里面: null, undefined, false, '' 的值都是false
    如果是 undefined的值是false的话
    那么if(a==false)测试结果该是相等的,我测试的结果不是相等的.
    但是 if(a==undefined) 结果却是相等的
    http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:    If Type(x) is the same as Type(y), then
            If Type(x) is Undefined, return true.
            If Type(x) is Null, return true.
            If Type(x) is Number, then
                If x is NaN, return false.
                If y is NaN, return false.
                If x is the same Number value as y, return true.
                If x is +0 and y is −0, return true.
                If x is −0 and y is +0, return true.
                Return false.
            If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false.
            If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.
            Return true if x and y refer to the same object. Otherwise, return false.
        If x is null and y is undefined, return true.
        If x is undefined and y is null, return true.
        If Type(x) is Number and Type(y) is String,
        return the result of the comparison x == ToNumber(y).
        If Type(x) is String and Type(y) is Number,
        return the result of the comparison ToNumber(x) == y.
        If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
        If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
        If Type(x) is either String or Number and Type(y) is Object,
        return the result of the comparison x == ToPrimitive(y).
        If Type(x) is Object and Type(y) is either String or Number,
        return the result of the comparison ToPrimitive(x) == y.
        Return false.
      

  7.   


    == 不检查类型,只检查值。
    在javascript里面: null, undefined, false, '' 的值都是false
    如果是 undefined的值是false的话
    那么if(a==false)测试结果该是相等的,我测试的结果不是相等的.
    但是 if(a==undefined) 结果却是相等的直接用if(a) 就可以了