JavaScript Equality Checker

Compare two JavaScript values side by side and instantly see the results of loose equality (==), strict equality (===), and Object.is(). Understand exactly when and why type coercion produces surprising results.

Try These Examples

  • "5" == 5 — String vs Number type coercion
  • null == undefined — Special equality rule in the spec
  • NaN === NaN — NaN is never equal to itself
  • 0 === -0 — Positive vs negative zero
  • true == "1" — Boolean coerces to number first
  • "" == 0 — Empty string coerces to 0
  • "" == false — Both coerce to 0
  • [] == false — Array coercion weirdness

How It Works

This tool parses your inputs based on the selected type, then runs all three JavaScript equality checks on the actual runtime values. The results you see are genuine JavaScript evaluations, not lookup tables.

Type Coercion and Loose Equality (==)

The == operator performs type coercion before comparing. When the two operands have different types, JavaScript follows a set of rules to convert one or both values to a common type. For example, comparing a string to a number converts the string to a number first. This can produce results that look wrong at first glance — "" == 0 is true because the empty string converts to 0.

Why === Is Generally Safer

The === operator (strict equality) never coerces types. If the two values have different types, the result is immediately false. This makes your code more predictable and easier to debug. Most style guides and linters recommend === by default. The one commonly accepted use of == is value == null, which matches both null and undefined.

Why NaN Is Special (IEEE 754)

JavaScript numbers follow the IEEE 754 double-precision floating-point standard. This standard defines that NaN (Not a Number) is unequal to every value, including itself. The rationale is that NaN represents an indeterminate result — two indeterminate results are not necessarily the same. Use Number.isNaN() or Object.is(value, NaN) to reliably test for NaN. You can also check whether a value is truthy or falsy to understand how NaN behaves in boolean contexts.

Object.is() — The Precise Check

Object.is() works like === but fixes two edge cases: it considers NaN equal to NaN, and it considers +0 and -0 to be different. This makes it the most semantically precise equality check in JavaScript.

Common Surprising Equality Comparisons

Expression=====Object.is()Why
"5" and 5truefalsefalseString coerces to number
null and undefinedtruefalsefalseSpecial spec rule for ==
NaN and NaNfalsefalsetrueIEEE 754; Object.is fixes this
+0 and -0truetruefalseObject.is distinguishes signed zeros
"" and 0truefalsefalseEmpty string coerces to 0
"" and falsetruefalsefalseBoth coerce to 0
true and "1"truefalsefalseBoolean becomes 1, string becomes 1
[] and falsetruefalsefalseArray coerces to "", then to 0
null and 0falsefalsefalsenull only == null or undefined
null and falsefalsefalsefalsenull only == null or undefined

Frequently Asked Questions

When should I use == vs ===?

In almost all cases, use === (strict equality). The == operator performs type coercion, which can lead to surprising and hard-to-debug results. For example, "" == 0 is true, and null == undefined is true. The only common exception is value == null, which conveniently catches both null and undefined in a single check.

Why is NaN not equal to NaN?

NaN is defined by the IEEE 754 floating-point standard, which JavaScript follows. The standard specifies that NaN is not equal to any value, including itself, because NaN represents an undefined or unrepresentable result. Two undefined results are not necessarily the same. Use Number.isNaN() or Object.is(value, NaN) to check for NaN reliably.

What does Object.is() do differently?

Object.is() is similar to === but handles two edge cases differently: Object.is(NaN, NaN) returns true (unlike ===), and Object.is(+0, -0) returns false (unlike ===). It performs no type coercion and is the most precise equality check in JavaScript.

Is my data sent to a server?

No. This tool runs entirely in your browser using JavaScript. Your input values never leave your machine. There are no server requests, no analytics on your input, and no data storage. You can verify this by checking the Network tab in your browser's developer tools.

Related Tools

← Back to all tools