References

Beginner-friendly references for web development, with live, editable examples.

The JavaScript Less Than Or Equal <= operator

Operator JavaScript All modern browsers Updated
Quick answer

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

Live 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

  • Use <= for inclusive upper bounds ("at most", "maximum").
  • Combine it with >= for an inclusive range.
  • Convert numeric strings with Number() before comparing.
  • Comparisons with NaN are always false.

Frequently asked questions

What does <= mean in JavaScript?
It returns 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 <= ?
< is strictly less; <= also returns true when the values are equal.
How do I write an inclusive range check?
Use x >= min && x <= max.
Does <= work on strings?
Yes — two strings compare alphabetically by character code. Convert to numbers for numeric comparison.