为什么null == 0输出false,因为两者都是假值?

时间:2016-06-27 08:56:45

标签: javascript comparison equality

当我跑步时

var validValues = [ 10, 20, 23, 27 ];
var statusType = json.properties.status.type;

/* This function call will return a boolean that tells you wether the value in your json is valid or not.*/
isValid( statusType ); 

function isValid( statusType )
{
  for( var i = 0; i < validValues.length; i++ )
    if( statusType === validValues[i] )
      return true;

  return false;
}

null == 0 

即使两者都是假值,两者都输出错误,为什么?

1 个答案:

答案 0 :(得分:-1)

==不仅会检查值,还会检查类型(而不是与===相同) 您可以在此处查看更多详细信息:The Abstract Equality Comparison Algorithm