I have an entry level question for javascript. When executing the following the result is
false
true
Some numbers are equal
number, number
numbernu
To do compound comparisons in JavaScript (or any other language syntactically derived from B), you don't do things like
(l>k>m) // <=== Wrong
Instead, if you want to know if l
is greater than k
and k
is greater than m
, you use &&
(the logical "and" operator), like this:
(l>k && k>m)
Details:
Your original expression (l>k>m)
breaks down into this:
((l>k)>m)
which means you'll get one of these:
(true>m)
// or
(false>m)
When comparing a boolean to a number, the boolean is coerced to a number, so that becomes in effect:
(1>m)
// or
(0>m)