The JavaScript Inequality != operator
The inequality operator != returns true when two values are not equal, after coercing their types — it's the negation of ==. Because it coerces, 0 != "" is false. Prefer strict inequality (!==), which doesn't coerce.
Overview
!= is simply the opposite of loose equality (==): it returns true when the two values are not equal. And it inherits exactly the same behavior — it coerces types before comparing. So 1 != "1" is false (they're "equal" after coercion), and 0 != "" is false too.
That carries the same confusion as ==, which is why the advice is identical: use strict inequality (!==) instead. It checks "not equal" without any type juggling, so 1 !== "1" is correctly true.
The only place you'll reasonably see != is the mirror of the == null idiom: x != null means "x is neither null nor undefined" — a concise "has a value" check. Outside that, default to !==.
Syntax
a != b
1 != "1" // false (coerced equal)
0 != "" // false
1 !== "1" // true (strict, preferred)
x != null // "x has a value" (not null and not undefined)
Example
<pre id="out" style="font:14px ui-monospace,monospace"></pre>
<script>
document.getElementById('out').textContent =
'1 != "1" -> ' + (1 != '1') + '\n' +
'1 !== "1" -> ' + (1 !== '1') + '\n' +
'5 != 5 -> ' + (5 != 5);
// false / true / false
</script>
Best practices
Frequently asked questions
What is the difference between != and !== ?
Why is 0 != "" false?
!= coerces, and 0 loosely equals "", so "not equal" is false. With !== it's true.What does x != null mean?
true when x is neither null nor undefined — a concise "x has a value" check.Should I ever use !=?
!= null idiom.