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 relational comparison operator that evaluates whether its left operand is numerically or lexicographically greater than or equal to its right operand. It strictly returns a boolean value (true or false).
leftOperand >= rightOperand

TypeScript Type Constraints

While JavaScript allows implicit type coercion across almost all types when using relational operators, TypeScript’s static type checker enforces strict operand compatibility to prevent unintended runtime coercion. To compile successfully, the operands must satisfy one of the following type conditions:
  1. Numeric and BigInt Types (number, bigint, numeric enum): Operands can be of type number, bigint, or a numeric enum member. TypeScript explicitly allows relational comparisons between number and bigint types.
  2. String Types (string): Both operands must be of type string.
  3. The any Type: If either operand is of type any, TypeScript bypasses strict type checking and defers to JavaScript’s standard runtime coercion rules.
Attempting to compare incompatible types (e.g., number and string), types that do not natively support relational comparison in TypeScript (like boolean), or object types (like Date), results in a compile-time error. To compare objects like Date instances, developers must explicitly convert them to comparable primitives.
// Valid numeric, bigint, and enum comparisons
const isNumGreater: boolean = 10 >= 10;       
const isBigIntGreater: boolean = 100n >= 50n; 
const mixedNumeric: boolean = 10n >= 5; // Valid: bigint and number

enum Level { Low = 1, High = 5 }
const isEnumGreater: boolean = Level.High >= Level.Low;
const isEnumNumGreater: boolean = Level.High >= 3; // Valid: enum and number

// Valid string comparison
const isStrGreater: boolean = "Z" >= "A";     

// Valid Date comparison (requires explicit primitive conversion)
const date1 = new Date("2024-01-02");
const date2 = new Date("2024-01-01");
const isDateGreater: boolean = date1.getTime() >= date2.getTime(); 

// Invalid type comparisons (Compile-time errors)
const invalidDateCompare = date1 >= date2; 
// TS2365: Operator '>=' cannot be applied to types 'Date' and 'Date'.

const mixedStrNum = 10 >= "5"; 
// TS2365: Operator '>=' cannot be applied to types 'number' and 'string'.

const bools = true >= false; 
// TS2365: Operator '>=' cannot be applied to types 'boolean' and 'boolean'.

Evaluation Mechanics

  • Numeric Evaluation (number, bigint, enum): Evaluates the mathematical value of the operands. If either operand evaluates to NaN, the comparison always returns false.
  • Lexicographical Evaluation (string): Compares strings character-by-character based on their UTF-16 code unit values. For example, "b" >= "a" evaluates to true because the code unit for “b” (98) is greater than “a” (97).
Master TypeScript with Deep Grasping Methodology!Learn More