You need two separate conditions, such as 5<2 && 2<1
for this to do what you're after. Without two conditions, you are comparing the result of the first condition against the right side of the second condition.
Why?
For the unexplained behaviour, I believe that the explanation for why it's returning what it's returning is the way javascript handles booleans (among other things) when used in numerical operations, in other words, javascript will cast your booleans to 0 or 1, there are a lot of examples of this in a few questions here at so, for example this one, you could do +false
and get a 0 for instance.
(5 < 2 < 1)
is true
because:
5<2
is resolved first, returning false
false
is cast to a number, returning 0
0<1
will return true
(5 > 2 > 1)
is false
because:
5>2
is resolved first, will return true
true
is cast to a number, will return 1
1>1
will return false