Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Equality Table

JavaScript has three main value-comparison operations: ==, ===, and Object.is(). Their results differ mainly in coercion, NaN handling, and the treatment of signed zero.

How it works

The page presents JavaScript's equality comparisons as a table of results for ==, ===, and Object.is(). Loose equality may convert values before comparing; strict equality does not, while Object.is() distinguishes signed zero and treats NaN as equal to itself.

Syntax

a == b; a === b; Object.is(a, b)

Returns

Each equality operation returns a boolean.

Key points

  • The table compares three operations: ==, ===, and Object.is().
  • Loose equality can convert operands before deciding whether they match.
  • For ordinary numbers, equality requires the same numeric value and excludes NaN.
  • The table includes special behavior for NaN and signed zero.
  • Reversing the operands of == does not change its result.

Example: Equality algorithms in practice

const values = [
  [0, false],
  ["0", false],
  [null, undefined],
  [NaN, NaN],
  [{}, {}]
];

for (const [a, b] of values) {
  console.log({
    a,
    b,
    loose: a == b,
    strict: a === b,
    sameValue: Object.is(a, b)
  });
}

Run this snippet to compare loose equality, strict equality, and Object.is for several edge cases.

When to use it

Predictable comparisons

Use === when comparing values in application logic where implicit coercion could hide bugs.

Nullable checks

Use == when intentionally accepting the documented null-or-undefined equivalence.

Edge-case numeric checks

Use Object.is() when NaN identity or signed-zero behavior matters.

Interview questions

QWhat is the difference between == and ===?

== permits type conversion, so values such as 0 and false can compare equal. === requires matching types and equal values without conversion.

Follow-up: How can NaN be tested reliably? Use Number.isNaN(value) for a type-safe NaN check, or Object.is(value, NaN) for the comparison semantics described by the page.

QHow are null and undefined compared?

null == undefined is true, while both values compare unequal to other values under loose equality. This is a special case in the comparison rules.

Follow-up: What does null === undefined return? false, because strict equality rejects operands of different types.

QWhen is Object.is() different from ===?

The equality table distinguishes strict equality from Object.is(). Object.is() treats NaN as equal to itself and distinguishes -0 from +0, unlike ===.

Follow-up: What does Object.is(-0, +0) return? false, because Object.is uses SameValue semantics for those numeric values.

  • Equality (==)
  • Strict equality (===)
  • Object.is()
  • SameValue
  • SameValueZero
  • IsLooselyEqual
  • IsStrictlyEqual

Source: Equality comparisons and sameness - JavaScript - MDN Web Docs. Checked 2026-10-15.