Course contentsShow
← JavaScript
Lesson 207 of 2,7236. Booleans and ConditionalsFree lesson

Greater/Less Than or Equal

Apply >= and <= operators for inclusive range comparisons and understand edge cases.

Greater Than or Equal and Less Than or Equal in JavaScript

You'll learn: How to use >= and <= operators to check if values meet or exceed thresholds, creating inclusive range comparisons.

What Are Inclusive Comparisons?

While > and < check strict boundaries (excluding the boundary value itself), >= and <= include the boundary in the comparison. Think of it like a height requirement for a ride: "You must be 48 inches or taller" uses >=, not just >.

The >= operator returns true if the left value is greater than or equal to the right value. Similarly, <= returns true if the left value is less than or equal to the right value.

Syntax and Examples

5 >= 5;    // true (equal counts!)
5 >= 3;    // true (greater works too)
5 >= 7;    // false

10 <= 10;  // true (equal counts!)
10 <= 15;  // true (less works too)
10 <= 8;   // false

Edge Cases to Remember

The "equal" part is crucial. This is where beginners often stumble:

0 >= 0;     // true (zero equals itself)
-5 <= -5;   // true (negatives too)

3.14 >= 3.14;  // true (floats work)

These operators follow the same type coercion rules as > and <:

"10" >= 5;   // true (string "10" converts to number)
"5" <= 10;   // true

Practical Use: Range Checking

These operators shine when checking if a value falls within a range:

let age = 18;
age >= 18;  // true (eligible)

let score = 100;
score >= 0 && score <= 100;  // true (valid score range)

Key Takeaway: Use >= and <= when your comparison should include the boundary value itself—they're essential for checking minimum requirements, maximum limits, and valid ranges.