0
Related to js
The precedence of && operator is greater than || operator, hence in following statement, && should be evaluated first, if it is, then why alert is not working as && finds first falsy value and alert evaluates to false. https://code.sololearn.com/WtvgkIgIrt3J/?ref=app
4 ответов
+ 3
Greater precedence means that the statements are captured with the following grouping/order:
(x > 0) || (alert("") && "hii")
So the short-circuit happens first, as anyone would want to.
+ 2
Some languages have short circuit, they evaluate from left to right to skip unneeded steps. If OR had greater precedence, the same would be evaluated first but the actual computation would be:
(x > 0 || alert("")) && ("hii")
AND also short-circuits on first failure instead of success.
0
Valen.H. ~ So as you said in first comment that && shoukd be executed first then the result should is execution of alert function as && operator finds first falsy value and alert function will evaluate to false.
0
If i set the value of x > 0 to x > 1, then alert function is executed, mening that, || operator is executing first regardless of higher precedence of && operator.