5

Can anyone tell me why

8>7<6 = true
12>10>2 = false

Please give answer enter image description here

Please Go through the image also

Thanks in Advance

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Rocky
  • 515
  • 1
  • 7
  • 18
  • In an MCQ interview they are asking these kind of stupid Question , they had given true false and error options Only – Rocky Jul 20 '18 at 09:05
  • 1
    `8>7` is `true` and `true < 6` is `true` so `(8>7)<6 = true`. `12>10` is `true` and `true>2` is `false` so `(12>10)>2 = false` – t.niese Jul 20 '18 at 09:06
  • I'm sorry for the messy comments guys. – Louys Patrice Bessette Jul 20 '18 at 09:15
  • 1
    It's a common misconception that there is a direct link between classical maths, & computer maths when it comes to writing them down,. The above in computer maths would be `8>6 && 7<6` and `12>10 && 10>2` – Keith Jul 20 '18 at 09:28

3 Answers3

8

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
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
6

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.

Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62
2

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
Tom Dee
  • 2,516
  • 4
  • 17
  • 25