[X]

Chained Comparisons Lie

luljs still works

1 < 2 < 3 is true, but 3 > 2 > 1 is false.

In 2026: Still works. JavaScript has no chained comparison; it evaluates left to right. 1 < 2 is true, and true coerces to 1, so 1 < 3 is true. But 3 > 2 is also true, which is 1, and 1 > 1 is false.

Where it came from: JavaScript evaluates comparisons left to right with no chaining, coercing each boolean result to a number for the next, as MDN's less-than page describes. MDN

<script>
document.write("<p><code>1 < 2 < 3</code> is <b>" + (1 < 2 < 3) + "</b></p>");
document.write("<p><code>3 > 2 > 1</code> is <b>" + (3 > 2 > 1) + "</b></p>");
document.write("<p>Each comparison returns a boolean that the next one treats as 1 or 0.</p>");
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›