Logical && and || operator precedence is broken
Posted: Fri Apr 07, 2017 3:11 pm
Not a big deal since you can always use parens, but just a heads up for people experiencing issues with this.
In Boolean algebra, the logical AND operator has higher order-of-operations precedence than logical OR. Therefore, the following two expressions should be equivalent:
In JSX, their results vary as indicated. The second expression is equivalent to this:
This does not follow logical order of operations. I confirmed that the two expressions both evaluate to true in other JavaScript engines.
In Boolean algebra, the logical AND operator has higher order-of-operations precedence than logical OR. Therefore, the following two expressions should be equivalent:
Code: Select all
(true && true) || (true && false) // Result: true
true && true || true && false // Result: false in JSX (should be true)
Code: Select all
((true && true) || true) && false