Who is Greater and Who is More Equal?

Comparison operators return a boolean value: true or false. Even if you compare strings, the result is always boolean.

1. The Basics

  • a > b, a < b — greater/less than.
  • a >= b, a <= b — greater/less than or equal to.
  • a == b — loose equality (coerces types).
  • a != b — loose " not equal " .

2. Strict Equality (===)

This is the " gold standard " of JS.

  • ==: Tries to coerce types to match. 0 == false returns true.
  • ===: Checks the type first. If types differ — immediately returns false. 0 === false returns false.

3. String Comparison

Strings are compared character by character in alphabetical order (more precisely, by Unicode character codes).

alert( 'Z' > 'A' ); // true
alert( 'Glow' > 'Glee' ); // true, because 'o' > 'e'
Important

Always use strict equality ===. This will save you from 90% of weird bugs.

Warning

null == undefined returns true (this is a special rule), but strict comparison null === undefined returns false.