Dual Or Triple (or Even Multiple) Comparison In Javascript
Almighty Gurus, Please tell me, I want to know can comparison sm. set of variables in row, like this: x < y >= z or i need to do it in two steps? (x < y) && (y &
Solution 1:
In Javascript, you must do this type of comparison in two steps.
Python is the only widely used language I'm aware of that allows the first form (please comment if I'm incorrect).
Solution 2:
Solution 3:
You should use 0 < -0.75 && -0.75 < 1
.
Because using a < b < c
is like doing (a < b) < c
.
Let explain your case:
0 < -0.75 < 1
- the first comparison (
0 < -0.75
) is processed, which returns false < 1
- then false is converted to number 0
0 < 1
which finally returns- true
Post a Comment for "Dual Or Triple (or Even Multiple) Comparison In Javascript"