JS中的“!!”

时间:2014-06-06 18:23:59   收藏:0   阅读:416
var o={flag:true};  var test=!!o.flag;//等效于var test=o.flag||false;  alert(test);

由于对null与undefined用!操作符时都会产生true的结果,
所以用两个感叹号的作用就在于,
如果明确设置了o中flag的值(非 null/undefined/0""/等值),自然test就会取跟o.flag一样的值;
如果没有设置,test就会默认为false,而不是 null或undefined

来源: http://www.cnblogs.com/iampoet/archive/2013/01/12/2857598.html

JS中的“!!”,布布扣,bubuko.com

原文:http://www.cnblogs.com/xxjudfc/p/3766233.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!