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 (>) operator is a binary relational operator that evaluates whether its left operand is strictly greater than its right operand, returning a boolean (true or false).
leftOperand > rightOperand
When evaluating the expression, JavaScript engine applies the Abstract Relational Comparison algorithm. This process dictates how different data types are coerced and compared:
  1. Primitive Conversion (ToPrimitive): Both operands are converted to primitive values. If an operand is an object, JavaScript attempts to convert it by calling its valueOf() and toString() methods, prioritizing numeric conversion.
  2. String Comparison: If both resulting primitives are strings, they are compared lexicographically based on their UTF-16 code unit values.
  3. Numeric Conversion (ToNumeric): If at least one of the primitives is not a string, both operands are coerced into numeric values (either Number or BigInt).
  4. NaN Evaluation: If either operand coerces to NaN (Not-a-Number), the operator strictly returns false.
  5. Zero Evaluation: JavaScript treats +0 and -0 as mathematically equal; neither is greater than the other.

Mechanical Examples

Strict Numeric Comparison Compares standard IEEE 754 double-precision floats or BigInts.
5 > 3;       // true
-1 > 0;      // false
10n > 9;     // true (BigInt and Number can be compared safely)
Lexicographical String Comparison Compares UTF-16 code units from left to right.
"b" > "a";   // true (98 > 97)
"Z" > "a";   // false (90 > 97 - uppercase letters have lower code units)
"10" > "2";  // false (Compares "1" and "2", 49 > 50 is false)
Type Coercion (Mixed Types) Forces numeric conversion when types do not match.
"5" > 3;     // true  (String "5" coerces to Number 5)
true > false;// true  (Boolean true coerces to 1, false to 0)
null > -1;   // true  (null coerces to 0)
Object Coercion Objects are reduced to primitives before comparison.
[5] > 4;     // true  (Array [5] coerces to String "5", then Number 5)
["a"] > 0;   // false (Array ["a"] coerces to "a", then NaN. NaN > 0 is false)
NaN Handling Any comparison involving NaN yields false.
NaN > 5;     // false
5 > NaN;     // false
NaN > NaN;   // false
undefined > 0; // false (undefined coerces to NaN)
Master JavaScript with Deep Grasping Methodology!Learn More