+ 14

How is the following code calculated in javascript?

var s= 12>5 || 54 && 0 && 1;

3rd Feb 2019, 11:13 AM
<αℓιяєzα />
<αℓιяєzα /> - avatar
3 Antworten
+ 9
The expression is evaluated from the left to the right, with && having a higher precedence than ||. var s= 12>5 || 54 && 0 && 1; => var s= 12>5 || ((54 && 0) && 1); => var s= 12>5 || ((false) && true); => var s= 12>5 || false; => var s= true || false; => var s= true;
3rd Feb 2019, 11:35 AM
Anna
Anna - avatar
+ 3
thank you,🙏🙏
3rd Feb 2019, 11:39 AM
<αℓιяєzα />
<αℓιяєzα /> - avatar
+ 2
Logical and has higher precedence than logical or. So the expression is evaluated as follows: 1. 54 && 0 is false (because 0 is falsy) 2. false && 1 is false 3. 12 > 5 is true 4. true || false is true So the result is true.
3rd Feb 2019, 11:39 AM
Division by Zero