• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Bug: Logical && and || operator precedence is broken

New Here ,
Apr 07, 2017 Apr 07, 2017

Copy link to clipboard

Copied

Not sure if this is the right place to report 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:

(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:

((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.

Workaround: Always use parens, but now I can't run my code through a minifier or obfuscator because it removes the extra parens to make the code smaller.

TOPICS
Actions and scripting

Views

888

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Apr 08, 2017 Apr 08, 2017

Copy link to clipboard

Copied

LATEST

This JSX is not JavaScript as you know it.

It has its own view of how it should work. 😄

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines