var i = 2;

Number.prototype.valueOf = function() {

return i++;

};

var a = new Number( 42 );

if (a == 2 && a == 3) {

console.log( "Yep, this happened." );

}

============================

"0" == null; // false

"0" == undefined; // false

"0" == false; // true -- UH OH!

"0" == NaN; // false

"0" == 0; // true

"0" == ""; // false

false == null; // false

false == undefined; // false

false == NaN; // false

false == 0; // true -- UH OH!

false == ""; // true -- UH OH!

false == []; // true -- UH OH!

false == {}; // false

"" == null; // false

"" == undefined; // false

"" == NaN; // false

"" == 0; // true -- UH OH!

"" == []; // true -- UH OH!

"" == {}; // false

0 == null; // false

0 == undefined; // false

0 == NaN; // false

0 == []; // true -- UH OH!

0 == {}; // false

[] == ![]; // true

2 == [2]; // true

"" == [null]; // true

0 == "\n"; // true

var a = null;

var b = Object( a ); // same as `Object()`

a == b; // false

var c = undefined;

var d = Object( c ); // same as `Object()`

c == d; // false

var e = NaN;

var f = Object( e ); // same as `new Number( e )`

e == f; // false

======================================================

ES5规范中的解释:

Comparing: objects to nonobjects

If an object/function/array is compared to a simple scalar primitive

(string, number, or boolean), the ES5 spec says in clauses

11.9.3.8-9:

1. If Type(x) is either String or Number and Type(y) is Object,

return the result of the comparison x == ToPrimitive(y).

2. If Type(x) is Object and Type(y) is either String or Number,

return the result of the comparison ToPrimitive(x) == y.

Comparing: nulls to undefineds

Another example of implicit coercion can be seen with == loose

equality between null and undefined values. Yet again quoting the

ES5 spec, clauses 11.9.3.2-3:

1. If x is null and y is undefined, return true.

2. If x is undefined and y is null, return true.

Comparing: anything to boolean

1. If Type(x) is Boolean, return the result of the comparison

ToNumber(x) == y.

2. If Type(y) is Boolean, return the result of the comparison x ==

ToNumber(y).

Comparing: strings to numbers

1. If Type(x) is Number and Type(y) is String, return the result of

the comparison x == ToNumber(y).

2. If Type(x) is String and Type(y) is Number, return the result of

the comparison ToNumber(x) == y.

==============================直观的比較图

http://dorey.github.io/JavaScript-Equality-Table/

最新文章

  1. Hololens 硬件细节 Hardware Detail
  2. UIApplication详解
  3. Adding a WebPart to a SharePoint 2013 Master Page 分类: Sharepoint 2015-07-08 01:03 7人阅读 评论(0) 收藏
  4. XCode一直显示"scanning for working copies"的解决办法
  5. Oracle Dataguard之failover
  6. php函数mt_rand和rand 速度测试
  7. 【转】beancopy的替代方案
  8. [string]Codeforces158C Cd and pwd commands
  9. nodejs上传图片模块做法;
  10. TCP/IP 和HTTP 协议基础知识
  11. FZU 2112 Tickets
  12. Swift 2.2 多态和强制转换
  13. Android学习总结——开篇
  14. 解决其他浏览器没有propertychange事件
  15. SSM-MyBatis-17:Mybatis中一级缓存(主要是一级缓存存在性的证明,增删改对一级缓存会造成什么影响)
  16. WPF 毛笔字
  17. 31.C++-虚函数之构造函数与析构函数分析
  18. IOS初级:story board的跳转
  19. 《C#本质论(第4版)》
  20. iis配置asp.net常见问题解决方案

热门文章

  1. python 多线程学习小记
  2. 洛谷 P1013 进制位
  3. boost::asio与ACE的对比
  4. 消灭星星的数组高效率算法(c++代码,控制台程序)
  5. cocos2d-x的声音控制
  6. js设计模式--------基本概念的理解
  7. ElasticSearch 架构图
  8. PHP表单生成器,快速生成现代化的form表单,快速上手
  9. Model、ModelMap、ModelAndView的作用及区别
  10. alert警告框