The JavaScript Less Than Or Equal <= operator
The <= operator returns true if the left value is less than or equal to the right. 5 <= 5 is true. It follows the same rules as < — numeric for numbers, alphabetical for two strings — and any comparison with NaN is false.
Overview
<= is less than with equality included: true when the left value is smaller than or exactly equal to the right. 5 <= 5 and 4 <= 5 are both true. Use it for inclusive upper bounds — "at most", "maximum", "up to and including".
It behaves like the other relational operators: numbers compare numerically, two strings compare alphabetically by character code, and mixed types coerce to numbers. As always, convert numeric strings with Number() when they come from inputs, and remember any comparison involving NaN is false.
It pairs with >= to express inclusive ranges, and rounds out the four relational operators alongside > and <.
Syntax
a <= b
5 <= 5 // true
4 <= 5 // true
6 <= 5 // false
// inclusive range check
x >= min && x <= max
Example
<pre id="out" style="font:14px ui-monospace,monospace"></pre>
<script>
const inStock = (qty) => qty <= 0 ? 'out of stock' : qty + ' left';
document.getElementById('out').textContent =
[0, 3, 10].map(q => q + ' -> ' + inStock(q)).join('\n');
// 0 -> out of stock / 3 -> 3 left / 10 -> 10 left
</script>
Best practices
Frequently asked questions
What does <= mean in JavaScript?
true if the left value is less than or equal to the right, e.g. 5 <= 5 is true.What is the difference between < and <= ?
How do I write an inclusive range check?
x >= min && x <= max.