short form of or condition comparison does not work anymore
Reported by
daniel....@ueberbit.de,
May 15 2018
|
|||
Issue description
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.170 Safari/537.36
Steps to reproduce the problem:
1. create a code which does a check varname === ('a' || 'b')
2. go to https://codepen.io/DanielRuf/pen/mLGVXr to see a real example
What is the expected behavior?
should evaluate to true if it is set to 'a' or 'b'
What went wrong?
does not evaluate to true anymore, condition fails, other browsers and previous versions did not have this issue
different results between previous releases and other browsers
Did this work before? N/A
Chrome version: 66.0.3359.170 Channel: stable
OS Version: OS X 10.13.4
Flash Version:
I'm sure that it worked before but can not find an old Canary release to test against.
,
May 15 2018
>It worked before so there was an actual change. The change was in how navigator.language is set in new Chrome, see bug 795680 , and adapt your code accordingly. >Firefox and others support this code and evaluate to true Parentheses mean that the enclosed expression is calculated prior to comparison and ('a' || 'b') always evaluates to 'a'. Then 'b' === 'a' will always be false. That's how JavaScript works. In all browsers.
,
May 15 2018
,
May 15 2018
woxxom@ is correct. Sorry for the confusion that the change in behavior of navigator.language has triggered, but || definitely has never behaved the way you describe.
,
May 16 2018
You are right. Sorry for the confusion. at least the navigator.language change introduced a regression. Thanks for the hint to the issue about the regression. |
|||
►
Sign in to add a comment |
|||
Comment 1 by woxxom@gmail.com
, May 15 2018('a' || 'b') evaluates to 'a' in all versions of JavaScript in all browsers. Hence, your code is equivalent to varname === 'a' It worked this way since forever. Here's the correct code for the behavior you want to achieve: varname === 'a' || varname === 'b' Judging by the codepen code, the confusion seems to be caused by the recent change in navigator.language, see bug 795680 .