+ 14
How is the following code calculated in javascript?
var s= 12>5 || 54 && 0 && 1;
3 odpowiedzi
+ 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;
+ 3
thank you,🙏🙏
+ 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.