tc39 / ecma262

Status, process, and documents for ECMA-262
https://tc39.es/ecma262/
Other
15.05k stars 1.28k forks source link

JavaScript Logical Operators - Short-circuit evaluation #1952

Closed mendezjose closed 4 years ago

mendezjose commented 4 years ago

Description: The expression "false && true || true" return true. But it should return false because of the short circuit evaluation.

eshost Output:

C:\Users\User\Documents\bug-report>eshost -s -x "const a = false && true || true; print(a)"
#### Chakra, SpiderMonkey, V8, V8 --harmony, XS
true

#### JavaScriptCore
bakkot commented 4 years ago

This is not a bug. false && true || true is evaluated as (false && true) || true, which is false || true, which is true.

(This also isn't the appropriate place for this kind of thing - might I recommend StackOverflow next time?)