Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The greater than or equal to (>=) operator is a binary relational operator that evaluates whether its left operand is mathematically or lexicographically greater than or equal to its right operand, returning a boolean (true or false).
leftOperand >= rightOperand
Under the hood, the ECMAScript specification evaluates x >= y by performing the Abstract Relational Comparison x < y (specifically IsLessThan(x, y, true)). If the result of that comparison is true or undefined (which occurs when an operand evaluates to NaN), the >= operator returns false. Otherwise, it returns true.

Evaluation Mechanics and Type Coercion

The operator applies the ToPrimitive abstract operation to both operands before comparing them. The subsequent behavior depends on the resulting primitive types: 1. Lexicographical String Comparison If both resulting primitives are strings, the operator compares them lexicographically based on their sequence of 16-bit unsigned integer values (UTF-16 code units).
"Z" >= "A";       // true  (UTF-16: 90 >= 65)
"apple" >= "bat"; // false (UTF-16: 97 >= 98 at index 0)
"10" >= "2";      // false (String comparison: "1" is less than "2")
2. Numeric Coercion If at least one of the primitive operands is not a string, JavaScript applies the ToNumeric operation to both operands, coercing them into Numbers or BigInts before performing a mathematical comparison.
10 >= "2";        // true  ("2" is coerced to Number 2)
true >= 1;        // true  (true is coerced to Number 1)
null >= 0;        // true  (null is coerced to Number +0)
undefined >= 0;   // false (undefined is coerced to NaN)
3. NaN Handling If either operand is NaN, or coerces to NaN, the underlying IsLessThan comparison returns undefined, causing the >= operator to strictly return false. This aligns with standard IEEE 754 math logic, where NaN is neither greater than, less than, nor equal to any value, including itself.
NaN >= 3;         // false
3 >= NaN;         // false
NaN >= NaN;       // false
"text" >= 0;      // false ("text" coerces to NaN)
4. BigInt and Number Comparison When comparing a Number and a BigInt, JavaScript compares their exact mathematical values without implicitly converting the BigInt to a Number. This prevents precision loss when comparing values beyond Number.MAX_SAFE_INTEGER.
10n >= 10;        // true
9007199254740992n >= 9007199254740992; // true
5. Object Coercion When an operand is an object, JavaScript attempts to convert it to a primitive by invoking its [Symbol.toPrimitive](), valueOf(), or toString() methods, in that specific order of precedence.
const obj = { valueOf: () => 5 };
obj >= 4;         // true (obj coerces to Number 5)

const date = new Date("2024-01-01");
date >= 1704067200000; // true (Date coerces to its numeric epoch timestamp)
Master JavaScript with Deep Grasping Methodology!Learn More