Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Greater-than operator (>)

The > operator checks whether the left operand is greater than the right operand. It returns a Boolean but may first convert its operands. Two strings are compared lexicographically rather than numerically.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

left > right

The expression left > right returns true when the left operand is greater than the right operand; otherwise it returns false, unless evaluation throws an exception. Equal values do not satisfy the condition: 3 > 3 produces false. The >= operator also includes equality.

Objects are first converted to primitive values with a number preference. If both resulting values are strings, comparison is lexicographic by UTF-16 code units, without language-specific collation: "20" > "3" produces false. Otherwise, numeric comparison rules apply; this is why "20" > 3 produces true. BigInt and Number values can be compared, for example 4n > 3.

A comparison involving NaN produces false; undefined becomes NaN in numeric comparison. Consequently, a > b does not always mean the same thing as !(a <= b). A Symbol value causes a TypeError, and object conversion can run user code and throw an exception.

Operands are evaluated from left to right; primitive conversion of the left operand also precedes conversion of the right operand. Therefore, do not assume that replacing a > b with b < a preserves side effects. Avoid chains such as a > b > c: they are parsed as (a > b) > c, so the second comparison receives a Boolean.

Examples

console.log(8 > 3);
console.log(3 > 3);
console.log("20" > "3");
console.log("20" > 3);
console.log(NaN > 0);
console.log(4n > 3);

Result

true
false
false
true
false
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources