Your confusion all comes down to a misunderstanding of precedence.
A mathematical analogue would be "Zero multiplied by anything equals zero." Consider the following expression:
0 x 100 + 5
In any programming language, or a decent calculator, this evaluates to 5. The "zero times anything" axiom is true - but the "anything" in this case is 100
, NOT 100 + 5
! To see why, compare it to this:
5 + 0 x 100
It doesn't matter whether you add the 5 at the beginning or the end - the operator precedence rules remove ambiguity from the statement.
In JavaScript boolean logic, &&
has higher precedence than ||
. Since each operator is commutative, writing
false && true || true
is exactly the same as writing
true || false && true