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