0

I'm currently learning JavaScript (Python background) and I'm having trouble on the logic behind stacking logic operators.

Let me explain.

In Python (61 <= 81 < 81) would output False. Which makes sense since it's basically (61 <= 81 AND 81 < 81).

But for some reason this same condition (61 <= 81 < 81) outputs True in JavaScript, almost as if it is reading it as (61 <= 81 OR 81 < 81) which is not expected. On the other hand if I explicitly write (61 <= 81 && 81 < 81) the output is False as expected.

Could anyone explain?

DjaouadNM
  • 22,013
  • 4
  • 33
  • 55
MrNobody
  • 19
  • 1

1 Answers1

3

The evaluation of 61 <= 81 < 81 is not comparing 81.

You have (61 <= 81) which is true and then it is true < 81

The only way to do what you want is to break it up into two checks with an AND

61 <= 81 && 81 < 81

epascarello
  • 204,599
  • 20
  • 195
  • 236