2025年03月03日 建站教程
逻辑运算符(&&, ||, !
):主要通过与、或、非来判断一个表达式的值是否为true。注意:与和或操作具有短路计算效果。下面web建站小编给大家详细介绍一下代码案例!
代码如下:
//短路计算 false && (anything) // 结果为false true || (anything) // 结果为anything //方法1: 设置x的缺省值 function test(x) { x = x || 100 } test(10) //x = 10 test() // x = 100 // 方法2: ES6的方式 function test(x = 100) { ... } test(10) //x = 10 test() // x = 100
本文链接:http://so.lmcjl.com/news/24188/