Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

JavaScript Comparison Operators: ==, ===, <, > Explained

JavaScript
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedSep 30, 2024
UpdatedNov 16, 2026
5 min read

JavaScript compares two values with the equality operators ==, ===, != and !==, and the relational operators <, >, <= and >=. Use === and !== for equality because they do not coerce types, and use the relational operators to order numbers, strings and other comparable values.

The original question lists the symbols <, >, == and ><. Note that >< is not a JavaScript operator, and <> (from SQL or Pascal) is not valid either. Use !== for "not equal".

Table of Contents

  • Equality operators
  • Relational operators
  • Comparing objects, arrays and dates
  • Locale-aware string comparison
  • Truthiness is not comparison
  • Practical rules
  • Frequently Asked Questions
    • Is there a not-equal operator like <> in JavaScript?
    • What is the difference between == and ===?
    • Why is NaN === NaN false?
    • Can I chain comparisons like 1 < x < 10?
  • Summary

Equality operators

OperatorMeaningCoerces types?ExampleResult
==Loose equalYes5 == "5"true
!=Loose not equalYes5 != "5"false
===Strict equalNo5 === "5"false
!==Strict not equalNo5 !== "5"true
javascript
javascript
Loading syntax highlighting...

Strict equality is the recommended default. NaN is never equal to anything, including itself, so test it with Number.isNaN() or Object.is().

Relational operators

The relational operators compare order:

javascript
javascript
Loading syntax highlighting...

There are no strict versions of these. If both operands are strings, they are compared by UTF-16 code unit order. Otherwise they are converted to numbers:

javascript
javascript
Loading syntax highlighting...

Comparing numeric strings as strings is a classic bug. Convert first with Number(value), or sort with a comparator.

Comparing objects, arrays and dates

Objects are compared by reference, not by content:

javascript
javascript
Loading syntax highlighting...

The relational operators work on dates because dates convert to timestamps, but equality needs getTime(). For deep comparison of data, compare fields or use a utility such as node:util isDeepStrictEqual in Node.js.

Locale-aware string comparison

Operators compare code units, so accented or case-sensitive text does not sort the way people expect. Use localeCompare or Intl.Collator:

javascript
javascript
Loading syntax highlighting...

Truthiness is not comparison

Conditions such as if (value) do not use the equality operators. They convert the value to a boolean, and these values are falsy: false, 0, -0, 0n, "", null, undefined and NaN. Everything else is truthy. Mixing the two ideas causes bugs:

javascript
javascript
Loading syntax highlighting...

Both lines for [] are correct, which shows why loose equality is hard to predict. Compare explicitly, for example list.length === 0.

Practical rules

  1. Use === and !== by default.
  2. Allow value == null only as a shortcut for null or undefined.
  3. Convert strings to numbers before relational comparison.
  4. Compare objects by field values or timestamps, not with ===.
  5. Enable the ESLint eqeqeq rule to enforce this.

Frequently Asked Questions

Is there a not-equal operator like <> in JavaScript?

No. Use !== for strict inequality or != for loose inequality.

What is the difference between == and ===?

== converts operand types before comparing, and === requires the same type and value. === is more predictable.

Why is NaN === NaN false?

By the IEEE 754 standard, NaN is not equal to any value, including itself. Use Number.isNaN(x).

Can I chain comparisons like 1 < x < 10?

It parses as (1 < x) < 10, which compares a boolean to 10 and is almost always wrong. Write 1 < x && x < 10.

Summary

  • JavaScript has loose (==, !=), strict (===, !==) and relational (<, >, <=, >=) operators.
  • There are no <> or >< operators.
  • Prefer strict equality and convert types explicitly before ordering values.
  • Compare objects by content and strings by locale when order matters.
Share