Inequality Operators: != and !==
You'll learn how to check if two values are not equal using JavaScript's inequality operators.
The Opposite of Equality
Just as JavaScript has two equality operators (== and ===), it has two inequality operators that work as their negated counterparts:
!==(strict inequality): Returnstrueif values differ in type or value!=(loose inequality): Performs type coercion before checking if values differ
Think of !== as the opposite of ===, and != as the opposite of ==. They mirror the same behavior, just flipped.
How They Work
// Strict inequality (!==)
5 !== 5 // false (same type and value)
5 !== "5" // true (different types)
true !== false // true (different values)
// Loose inequality (!=)
5 != 5 // false (same value)
5 != "5" // false (coerces "5" to 5, then compares)
5 != 6 // true (different values)
When to Use Which
Just like with equality, prefer !== in almost all cases. It's predictable and prevents type coercion surprises:
0 != false // false (coerces both to numbers, 0 === 0)
0 !== false // true (number vs boolean — different types)
null != undefined // false (special case: they're "equal" with !=)
null !== undefined // true (different types)
Key Takeaway: Use !== for strict inequality checks that don't perform type coercion, and avoid != unless you specifically need its coercion behavior—it's the negated version of === and == respectively.