Greater than or equal (>=)
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The greater than or equal (>=
) operator returns true
if
the left operand is greater than or equal to the right operand, and false
otherwise.
Try it
Syntax
js
x >= y
Description
The operands are compared using the same algorithm as the Less than operator, with the result negated. x >= y
is generally equivalent to !(x < y)
, except for two cases where x >= y
and x < y
are both false
:
- If one of the operands gets converted to a BigInt, while the other gets converted to a string that cannot be converted to a BigInt value (it throws a syntax error when passed to
BigInt()
). - If one of the operands gets converted to
NaN
. (For example, strings that cannot be converted to numbers, orundefined
.)
x >= y
is generally equivalent to x > y || x == y
, except for a few cases:
- When one of
x
ory
isnull
, and the other is something that's notnull
and becomes 0 when coerced to numeric (including0
,0n
,false
,""
,"0"
,new Date(0)
, etc.):x >= y
istrue
, whilex > y || x == y
isfalse
. - When one of
x
ory
isundefined
, and the other is one ofnull
orundefined
:x >= y
isfalse
, whilex == y
istrue
. - When
x
andy
are the same object that becomesNaN
after the first step of Less than (such asnew Date(NaN)
):x >= y
isfalse
, whilex == y
istrue
. - When
x
andy
are different objects that become the same value after the first step of Less than:x >= y
istrue
, whilex > y || x == y
isfalse
.
Examples
String to string comparison
js
"a" >= "b"; // false
"a" >= "a"; // true
"a" >= "3"; // true
String to number comparison
js
"5" >= 3; // true
"3" >= 3; // true
"3" >= 5; // false
"hello" >= 5; // false
5 >= "hello"; // false
Number to Number comparison
js
5 >= 3; // true
3 >= 3; // true
3 >= 5; // false
Number to BigInt comparison
js
5n >= 3; // true
3 >= 3n; // true
3 >= 5n; // false
Comparing Boolean, null, undefined, NaN
js
true >= false; // true
true >= true; // true
false >= true; // false
true >= 0; // true
true >= 1; // true
null >= 0; // true
1 >= null; // true
undefined >= 3; // false
3 >= undefined; // false
3 >= NaN; // false
NaN >= 3; // false
Specifications
Specification |
---|
ECMAScript Language Specification # sec-relational-operators |
Browser compatibility
BCD tables only load in the browser