Can anyone tell me why
8>7<6 = true
12>10>2 = false
Please Go through the image also
Thanks in Advance
Can anyone tell me why
8>7<6 = true
12>10>2 = false
Please Go through the image also
Thanks in Advance
Here true = 1
and false =0
and expression evaluate from left to right
1) 8>7<6 = true
8>7 = true
true<6 = 1<6=true
2) 12>10>2 = false
12>10=true
true>2 = 1>2= false
In javascript the comaprison expression is evaluated from leftmost to right so
When you do 8 > 7 < 6
, it undergoes the steps:
8 > 7 //true
true < 6 // true, since boolean value true is 1
Similarly when you do 12 > 10 >2
, it undergoes the steps:
12 > 10 //true
true > 2 //false, since boolean value true is 1
Furthermore, you cannot assume that 12 > 10 > 2
will evaluate as a whole.
As the other answers are saying, it will be evaluated from left to right so:
8 > 7 // true
true < 6 // true
But if you want the statement to read more mathematically logically you would need to split up the comparisons like:
8 > 7 && 7 < 6 //false