數(shù)值參與邏輯運(yùn)算
<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;
//數(shù)值參與邏輯運(yùn)算符,如果是&&,r如果結(jié)果為真买窟,那么會(huì)返回第二個(gè)為真的值丰泊,如果是假,返回第一個(gè)為假的值始绍;
//||
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;
//如果是||,如果結(jié)果為真吞杭,那么返回的第一個(gè)為真的值盏浇,如果為假,那么返回第二個(gè)為假的值芽狗;
</script>