zoukankan      html  css  js  c++  java
  • 如果理解&&运算符和各类数值的布尔值

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

    短路原则:例如 : a && b;   当a为true时,程序无论如何都会走b,而不管b为true或者false ,直接返回b ,当a为fasle时,程序会走a,直接返回a。

    ||   (或运算符):

    “||”运算遇到true就返回。例如:a || b ,如果 a 为false,直接返回b,而不管b为true或者false 。如果 a 为true,直接返回a,而不会继续往下执行。

    <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);

  • 相关阅读:
    PHP输出日志,json美化
    php获取项目路径
    16进制颜色,正则
    doctrine/instantiator
    cn.archive.ubuntu.com 慢的问题
    yzalis/identicon 像素头像
    Shell 判断进程是否存在
    shell 2>&1
    shell 判断是否继续
    shell
  • 原文地址:https://www.cnblogs.com/8080zh/p/9227452.html
Copyright © 2011-2022 走看看