JavaScript Tips: == vs ===

等于操作符 ==

会进行强制类型转换

""=="0"    //false
0==""    //true
0=="0"    //true
false == "false"    //false
false =="0"    //true
false==undefined    //false
false == null    //false
null==undefined     //true
" \t\r\n"==0    //true
当其中有一个操作符为对象时:
{} =={}    //false
new String('foo') == 'foo'    //true
new Number(10) == 10    //true
var foo ={};
foo == foo    //true

 

严格等于操作符 ===

不会进行强制类型转换,类型不同即为不等。

""==="0"    //false
0===""    //false
0==="0"    //false
false === "false"    //false
false ==="0"    //true
false===undefined    //false
false === null    //false
null===undefined     //false
" \t\r\n"===0    //false
当其中有一个操作符为对象时:
{} =={}    //false
new String('foo') == 'foo'    //false
new Number(10) == 10    //false
var foo ={};
foo == foo    //true

 

参考链接:

http://bonsaiden.github.io/JavaScript-Garden/zh/#object.general

 

posted @ 2017-02-08 17:27  Jane&Coding  阅读(138)  评论(0)    收藏  举报