如果理解&&运算符和各类数值的布尔值

&&(且运算符):表示二者都为true才为true;

<2>

在js中  0/“”/‘’/null/false/undefined/NaN 的布尔值都是false

其余的皆为true;

Boolean(“”)===false; boolean(NaN)=false;

Boolean(123)===true;(三目运算符判断类型)

例如:

Function  abc(data){

   !data && console.log(1);             //当!data==true时  执行console.log(1);

}

当执行 abc(“”)时 boolean(“”)=false; !false=true; 则 执行console.log(1);

猜你喜欢

转载自www.cnblogs.com/8080zh/p/9227452.html