<= not associative, so you cannot use it by repeating. You can specify it with:
1 <= month && month <= 12
The reason is because the JavaScript parser parses 1 <= month <= 12 as:
(1 <= month) <= 12
This is a consequence of the JavaScript grammar, they could define it differently, but that would complicate things a bit. Most grammars define expressions as:
expr -> [0-9]+ expr -> identifier expr -> expr '<=' expr
(with LALR).
And Java uses the following (approximate) grammar:
expr -> numExpr '<=' numExpr expr -> numExpr numExpr -> identifier numExpr -> [0-9]+ (...and so on...)
In Java, in this way, it is even impossible to parse such an expression (unless you make a throw that numExp will make it numExp ).
For the JavaScript part, why does it always return true ?
Now (1 <= month) is logical (true / 1 or false / 0 ), and this value cannot compare (reasonably) with 12 ( 0 and 1 always less than or equal to 12 ). Only very limited programming languages ββare supported.
source share