数值参与逻辑运算
<script>
var a = 5;
var b = 10;
var c = 0;
var d = 0;
//&&
var ab = a && b;
var ba = b && a;
var ac = a && c;
var bc = b && c;
console.log(ab);//10;
console.log(ba);//5;
console.log(ac);//0;
console.log(bc);//0;
//数值参与逻辑运算符,如果是&&,r如果结果为真,那么会返回第二个为真的值,如果是假,返回第一个为假的值;
//||
var ab1 = a || b;
var ba1 = b || a;
var ac1 = a || c;
var bc1 = b || c;
var cd1 = c || d;
console.log(ab1);//5;
console.log(ba1);//10;
console.log(ac1);//5;
console.log(bc1);//10;
console.log(cd1);//0;
//如果是||,如果结果为真,那么返回的第一个为真的值,如果为假,那么返回第二个为假的值;
</script>