Hi, in a conditional statement, I want to check whether a value is between two other values.
It seems the only way to write it is (5<=myVar && myVar<10)
.
Why can’t I just write something like (5<=myVar<10)
?
Also, which book or reference could I look at (besides this forum) that would tell me this information?
JavaScript interprets expressions “on-the-go” based on it’s order of operations.
Actually, in this specific case, (5<=myVar<10)
is true for literally any value (even undefined
or NaN
). That’s because 5<=myVar
gets converted to a boolean value (1 or 0), either of which is smaller than 10.
I don’t have a source, but hopefully that helps.
1 Like
Hi OzRamos, thank you for explaining the “on-the-go” evaluation and that the first part gets converted to a 1 or 0. That was super clear and helpful! Now I understand why the code in that block kept running!
1 Like
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.