JS之逻辑运算符代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS之逻辑运算符代码</title>
</head>
<body>
<script>
/******************* JS之逻辑运算符代码 **********************/
//定义变量
var a=1, b=2, c=3, d=false;
/*if(c && a){
console.log('true');
}else{
console.log('false');
}*/
//下面这种形式的表达式,输出为一个结果,这是结果是a的值或者b的值。
// 假如a为ture,a不能决定结果,再看b,因为b决定结果,所以输出b。谁决定结果就输出谁
console.log(a&&b); //结果:2
console.log(a&&c); //结果:3
console.log(c&&a); //结果:1
console.log(a||b); //结果:1
console.log(c||a); //结果:3
console.log(c||d); //结果:3
</script>
</body>
</html>