Skip to content

JavaScript greater than or equal to | Operator

  • by

JavaScript greater than or equal to operator (>=) returns true if the left operand is greater than or equal to the right operand, and false otherwise.

x >= y

Since Greater-than or Equal-to operator returns a boolean value, the above expression can be used as a condition in If-statement.

if (operand1 >= operand2) {
    //code
}

JavaScript greater than or equal to

Simple example code take two values in variables: x and y; and check if the value in x is greater than or equal to that of in y.

<!DOCTYPE html>
<html>
<body>
  <script>
    var x = 'apple';
    var y = 'banana';

    if (x >= y) {
      res = 'x is greater than or equal to y.';
    } else {
      res = 'x is not greater than or equal to y.';
    }
    
    console.log(res);
    
  </script>
</body>
</html>

Output:

JavaScript greater than or equal to Operator

More Examples

console.log(5 >= 3); // true

console.log(3 >= 3); // true

// Compare bigint to number
console.log(3n >= 5); // false

console.log('ab' >= 'aa'); // true

String to string comparison

console.log("a" >= "b");     // false
console.log("a" >= "a");     // true
console.log("a" >= "3");     // true

String to number comparison

console.log("5" >= 3);       // true
console.log("3" >= 3);       // true
console.log("3" >= 5);       // false

console.log("hello" >= 5);   // false
console.log(5 >= "hello");   // false

Number to Number comparison

console.log(5 >= 3);         // true
console.log(3 >= 3);         // true
console.log(3 >= 5);         // false

Comparing Boolean, null, undefined, NaN

console.log(true >= false);  // true
console.log(true >= true);   // true
console.log(false >= true);  // false

console.log(true >= 0);      // true
console.log(true >= 1);      // true

console.log(null >= 0);      // true
console.log(1 >= null);      // true

console.log(undefined >= 3); // false
console.log(3 >= undefined); // false

console.log(3 >= NaN);       // false
console.log(NaN >= 3);       // false

Do comment if you have any doubts or suggestions on this Js compression operator.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *