zoukankan      html  css  js  c++  java
  • 短路运算符

    js中的短路运算符主要是&&和||

    &&

    1.左边的值经过boolean运算为true,返回右边的值

    eg: 

    var a= 1 && "bb";

    console.log(a); //bb

    2.左边的值为null、undefined或NaN,返回null、undefined或NaN

    eg:

    var a= null && "34343";

    console.log(a); //null

    3.左边的值经过Boolean运算为false,返回左边的值

    eg:

    var a= 1;

    var b= a> 10 && a< 5;

    console.log(b); //false

    --------------------------------------------------------------------------------------------------------------

    ||

    1.左边的值Boolean运算为true,返回左边的值

    eg:

    var a= 5 || 6;

    console.log(a);

    2.左边的值Boolean运算为false,返回右边的值

    var a= 1;
    var b= a>6 || NaN;
    console.log(b); //NaN

    3.左边为null、undefined、NaN,返回右边的值

    eg:

    var b= NaN || undefined;
    console.log(b); //undefined

  • 相关阅读:
    从up6-down2升级到down3
    XproerIM产品使用手册
    Web大文件上传控件-asp.net-bug修复-Xproer.HttpUploader6.2
    WordPaster-Chrome浏览器控件安装方法
    poj1009
    poj1012
    poj1016
    poj1019
    poj1023
    poj1026
  • 原文地址:https://www.cnblogs.com/yanze/p/6349851.html
Copyright © 2011-2022 走看看