JavaScript Comparison

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Relational comparison operators test order: <, >, <=, and >=. They return a boolean. For equality, prefer === (see the equality page).

JavaScript Syntax

JavaScript
console.log(3 < 5);
console.log(3 >= 3);
console.log("a" < "b");
Try it Editor

How It Works

  1. Numbers. Compared by numeric value.
  2. Strings. Compared by Unicode order.

Examples

Example 1 — Numbers

Simple ordering.

JavaScript
console.log(10 > 2);
console.log(10 <= 9);
Try it Editor

How It Works

  1. 10 is greater than 2.
  2. 10 is not <= 9.

Example 2 — Type coercion

Mixed types convert to numbers when possible.

JavaScript
console.log("10" > 2);
Try it Editor

How It Works

  1. "10" becomes 10.

Example 3 — Prefer === for equality

Use the equality operators page for == / ===.

JavaScript
console.log(1 === 1);
Try it Editor

How It Works

  1. Strict equality does not coerce types.

Frequently Asked Questions

It uses Unicode code-unit order, which may differ from locale-aware sorting.
See Operators equality and Concepts equality.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful