Such code in JS 10 <= x <= 100
for any number x
will always return true
.
How is it called ? Why does it behave like this ? Where can I found some doc about it ?
Is 10 <= x && x <= 100
the shortest way to do things properly ?
Such code in JS 10 <= x <= 100
for any number x
will always return true
.
How is it called ? Why does it behave like this ? Where can I found some doc about it ?
Is 10 <= x && x <= 100
the shortest way to do things properly ?
See Abstract Relational Comparison
10 <= x
is going to be true
or false
.
Then someBoolean <= 100
is going to cause the boolean to be converted to a number 1
or 0
.
Both 1
and 0
are less than 100
.
If you want to do two comparisons of a number then you need to explicitly make two comparisons and combine them with &&
, not by simply mashing them together.
10 <= x && x <= 100