I wanted further clarification on something.
Consider this:
var a = 42;
var b = "abc";
var c = null;
a || b; // 42
a && b; // "abc"
c || b; // "abc"
c && b; // null
I know that for the ||
operator, if the test on the first operand is true, the ||
expression results in the value of the first operand (a or c). If the test is false, the ||
expression results in the value of the second operand (b).
Inversely, for the &&
operator, if the test is true, the &&
expression results in the value of the second operand (b). If the test is false, the &&
expression results in the value of the first operand (a or c)
So what exactly is happening when you use the &&
and ||
operators with chaining values like:
if(a && b && c && d && e){
//do something;
}
if(a || b || c || d || e){
//do something
}
What exactly is taking place when you chain the values? Because in the first example (involving the &&
operator)if a is true, then b should be returned right? so are c or d even taken into account at that point?