Logical && and || operator precedence is broken

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

Moderators: xbytor, DavideBarranca, Paul MR

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

Logical && and || operator precedence is broken

Postby nfrasser » 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:

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.

Return to “Photoshop Scripting Bugs and Anomalies”

Who is online

Users browsing this forum: No registered users and 1 guest