3

Why does (10<3<10) return true in Javascript? 3<10 but 10<3 is false. So it should return false

AlieN
  • 555
  • 2
  • 16
  • 2
    Actually, the reason it should return false is because 10 cannot possibly `<3` being less than 10 because 10 *is not less than* 10. – BoltClock Apr 11 '14 at 17:50
  • Most languages don't support the double comparison like that. – Sam G-H Apr 11 '14 at 17:50
  • You can't really use two operators, so operator presedence kicks in, and it's read `( (10<3) < 10 )` which equals `( false < 10 )` which is true – adeneo Apr 11 '14 at 17:50
  • @BoltClock, `4<3<10` also true) – vp_arth Apr 11 '14 at 17:51
  • This has been asked and answered here on SO at least once before, but I don't have the link handy. *Edit*: Oh, hey, it was right there in the "related" list. Which means it was on the "Your question may already have an answer" list shown to you before you posted the question. – T.J. Crowder Apr 11 '14 at 17:52
  • I am sorry. I am a newbie))) (registered yesterday)! – AlieN Apr 11 '14 at 17:57
  • because zero is less than 3... – dandavis Apr 11 '14 at 18:00

2 Answers2

11

10<3<10 is equivalent to (10<3)<10. 10<3 is false, false<10 is true.

hobbs
  • 223,387
  • 19
  • 210
  • 288
2

because

Number(false)

is 0 and 10<3 is false.

kojiro
  • 74,557
  • 19
  • 143
  • 201