zoukankan      html  css  js  c++  java
  • js 非布尔值操作 逻辑与 和 逻辑或*

    /*js 非布尔值操作 逻辑与 和 逻辑或*/
    /*
    * 注:( "" , 0 ,undefined ,NaN ,null 转换为 false)
    * */
    /*逻辑与*/
    console.log(( 1 && 1 && "hello" && 2 && 3 && 4 )); // 第一个转换为true 返回 最后一个值 (4)
    console.log(( 0 && 0 && "hello" && 2 && 3 && 4 )); //第一个转换为 false 返回 第一个值(0)
    console.log((1 && 2 && 3 && null && NaN));// 操作值中 有 null NaN undefined 其中的之一 返回这个值(有多个取最前) //返回null

    /* 逻辑或*/
    console.log(( 1 || 1 || "hello" || 2 || 3 || 4 )); // 第一个转换为true 返回 第一个值 (1)
    console.log(( 0 || 0 || "hello" || 2 || 3 || 4 )); //第一个转换为 false 返回 第一个转换为true的值(hello)
    console.log(( 0 || 0 || "" || undefined || NaN || null )); //全部转换为 false 返回 最后一个(null)
  • 相关阅读:
    图片《小美眉》
    redhat基本知识
    Linux 求助。设置分辨率?

    PHP close
    别想一个人承担一切
    java charAt返回char,不是int
    我的计算器
    支付宝面试小贴士
    java string charAt length()疑惑
  • 原文地址:https://www.cnblogs.com/hellozg/p/7169271.html
Copyright © 2011-2022 走看看