Logical && and || operator precedence is broken

Discussion of actual or possible Photoshop Scripting Bugs, Anomalies and Documentation Errors

Moderators: xbytor, Kukurykus, Tom

nfrasser
Posts: 2
Joined: Fri Jan 20, 2017 5:13 pm

Logical && and || operator precedence is broken

Post by nfrasser »

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:

Code: Select all


(true && true) || (true && false) // Result: true
true && true || true && false // Result: false in JSX (should be true)
In JSX, their results vary as indicated. The second expression is equivalent to this:

Code: Select all


((true && true) || true) && false
This does not follow logical order of operations. I confirmed that the two expressions both evaluate to true in other JavaScript engines.