JavaScript中==和===区别

在我们的日常编码中对于===是不常用的,但是它很重要

===:表示绝对相等(严格)

!==:表示不绝对相等

==:表示相等(不严格)

!=:表示不相等

看一下列子:

null==undefined  结果是为true

null===undefined 结果是为false

0==false,0=='',''==false 结果都是为true

0===false,0==='',''===false 结果都是为false

 

反之:!=和!==结果和上面相反

 

 

测试代码:

alert("null==0 is "+(null==0)+"\n"+"null==undefined is "+(null==undefined)+"\n"+"null=='' is "+(''==null)+"\n"+"null==false is "+(null==false)+"\n"+"0=='' is "+(0=='')+"\n"+"0==false is "+(0==false)+"\n"+"0==undefined is "+(0==undefined)+"\n"+"''==false is "+(''==false)+"\n"+"''==undefined is "+(''==undefined)+"\n"+"false==undefined is "+(false==undefined));

alert("null===0 is "+(null===0)+"\n"+"null===undefined is "+(null===undefined)+"\n"+"null==='' is "+(''===null)+"\n"+"null===false is "+(null===false)+"\n"+"0==='' is "+(0==='')+"\n"+"0===false is "+(0===false)+"\n"+"0===undefined is "+(0===undefined)+"\n"+"''===false is "+(''===false)+"\n"+"''===undefined is "+(''===undefined)+"\n"+"false===undefined is "+(false===undefined));

posted on 2014-04-09 11:24  佬叁  阅读(146)  评论(0编辑  收藏  举报

导航