码迷,mamicode.com
首页 > 其他好文 > 详细

对null,undefined取反的常见情况分析

时间:2018-06-25 15:04:35      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:log   def   []   ===   define   分析   null   常见   alert   

1.对空数组判断

var aa=[];
if(aa){  //此时aa为真,所以继续执行
    console.log(23423);
}

2.对字面量声明的空对象判断

var bb = {};
if(bb){ //此时bb为真,继续执行
    alert(234);
}

3.对null对象判断

var cc=null;
if(!cc){ // 此时cc为假,取反为真,继续执行
    alert(34);
}

4.对undefined判断

var dd = undefined;
if(!dd){ // 此时dd为假,取反为真,继续执行
    alert("可以执行");
}

5.其他判断条件

console.log(null=={}); // false
console.log(null==undefined); // true
console.log(null===undefined); // false

对null,undefined取反的常见情况分析

标签:log   def   []   ===   define   分析   null   常见   alert   

原文地址:https://www.cnblogs.com/bonly-ge/p/9223817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!