Skip to main content
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).
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.
Lexicographical String Comparison Compares UTF-16 code units from left to right.
Type Coercion (Mixed Types) Forces numeric conversion when types do not match.
Object Coercion Objects are reduced to primitives before comparison.
NaN Handling Any comparison involving NaN yields false.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More