I am checking for the values of AND operator in javascript, the below code for some reason returning 0. Can someone explain actual behavior of AND operator here?
var result = 88 && 6 && 0 && null && 9;
alert(result);
I am checking for the values of AND operator in javascript, the below code for some reason returning 0. Can someone explain actual behavior of AND operator here?
var result = 88 && 6 && 0 && null && 9;
alert(result);
&&
evaluates as the left hand side if the left hand side is false, otherwise it evaluates as the right hand side.
(88) && (6 && 0 && null && 9)
88 is true, so the right hand side is evaluated.
(6) && (0 && null && 9)
6 is true, so the right hand side is evaluated.
(0) && (null && 9)
0 is false, so it is the result.