Though the short circuit evaluation coerces to Boolean
for evaluation, the operators
actually returns the value
of one of the specified operands
If this operator
is used with non-Boolean values
, it will return a non-Boolean value
A || B
true || true; // true true || false; // true false || false; // false
A
is true
, it evaluates to A
A
is true
and B
is true
, it evaluates to A
A
is true
and B
is false
, it evaluates to A
A
is false
, it evaluates to B
A
is false
and B
is true
, it evaluates to B
A
is false
and B
is false
, it evaluates to B
A && B
// returns first falsy element otherwise they return last element 1 && 0 && false // 0 1 && 2 && 3 // 3 (last)
When A
is true, it evaluates to B
A
is true
and B
is true
, it evaluates to B
A
is true
and B
is false
, it evaluates to B
When A
is false
, it evaluates to A
A
is false
and B
is true
, it evaluates to A
A
is false
and B
is false
, it evaluates to A
&&
and ||
Interchangeability// && to || bCondition1 && bCondition2 // is always equal to: !(!bCondition1 || !bCondition2) // || to && bCondition1 || bCondition2 // is always equal to: !(!bCondition1 && !bCondition2)