The JavaScript Strict Inequality !== operator
The strict inequality operator !== returns true when two values are not strictly equal — different type or different value, with no coercion. 1 !== "1" is true. It's the negation of === and the not-equal check you should use by default.
Overview
!== is the strict, no-surprises "not equal." It's the negation of strict equality (===): it returns true unless the two values have the same type and the same value. Because it never coerces, 1 !== "1" is true (a number is not a string), which is exactly what you'd expect.
This is the not-equal operator to reach for by default, the partner to ===. Together they give predictable comparisons with none of the type-juggling that makes == and != error-prone.
The usual comparison caveats apply: objects compare by reference, so two look-alike objects are !== even with identical contents; and anything compared to NaN is unequal, so NaN !== NaN is true (use Number.isNaN() to test for NaN).
Syntax
a !== b
1 !== "1" // true (different types)
5 !== 5 // false
{} !== {} // true (different references)
NaN !== NaN // true
Example
<pre id="out" style="font:14px ui-monospace,monospace"></pre>
<script>
const role = 'admin';
if (role !== 'admin') {
document.getElementById('out').textContent = 'access denied';
} else {
document.getElementById('out').textContent = 'welcome, admin';
}
</script>
Best practices
- Use
!==as your default not-equal check — it avoids coercion. - Pair it with ===; avoid != and ==.
- Remember objects compare by reference, so compare their fields to check contents.
- Test for
NaNwith Number.isNaN(), not!==.
Frequently asked questions
What does !== do in JavaScript?
true when two values are not strictly equal — different type or value — without any type coercion.What is the difference between != and !== ?
Why is 1 !== "1" true?
!== doesn't coerce, so they're considered not equal.Why are two identical objects !== ?
!== is true.