For example(may be too unrealistic)
var a=1;
var b=4;
var c=5;
var d=6;
a>2&&!b<5||c=5&&d>6
A simple google search yields a table with all the operations and there precedence:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
a > 2 && ! b < 5 || c = 5 && d > 6
The unrealistic part is c = 5
which is not an expression so cannot be an operand in the above. c === 5
is an expression.
! b < 5
will always be true
since both false and true are less than 5.
The NOT b is evaluated first resulting in a boolean.
> false < 1
<- true
> true < 1
<- false
> true < 2
<- true
NOT is the first thing evaluated in your overall expression, followed the comparisons, then by AND, and finally by OR.
a = b = c = d = 0
a > 2 && ! b < 5 || c = 5 && d > 6
becomes,
false && true || false && false
which becomes,
false || false
which is false
.
1 Like
Thank you for your answer!! I really appreciate that! stetim94 has a reference which shows a more general case.
1 Like