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)
  • 相关阅读:
    四则运算网页版
    第六周工作日志
    课堂作业数组最大和
    第五周总结
    四则运算三结对开发
    学习进度第四周
    个人模块记录表
    学习进度表第三周
    四则运算第二篇
    保序回归问题
  • 原文地址:https://www.cnblogs.com/hellozg/p/7169271.html
Copyright © 2011-2022 走看看