Course contentsShow
← JavaScript
Lesson 205 of 2,7236. Booleans and ConditionalsFree lesson

Inequality: != vs !==

Understand loose (!==) and strict (!==) inequality operators and their relationship to equality checks.

Inequality: != vs !==

You'll learn the two ways to check if values are not equal in JavaScript — and why one is safer than the other.


Just like equality has two operators (== and ===), inequality also has two: loose inequality (!=) and strict inequality (!==).

The Core Difference

  • != (loose inequality) returns true if values are different after type coercion
  • !== (strict inequality) returns true if values are different in value OR type (no coercion)

These are simply the opposites of == and ===. Whatever would make == return false, != returns true. Whatever would make === return false, !== returns true.

5 != "5"    // false — types coerced, values equal
5 !== "5"   // true  — types differ, strictly not equal

0 != false  // false — coerced to same value
0 !== false // true  — number vs boolean, different types

null != undefined  // false — special case, coerced as equal
null !== undefined // true  — different types, strictly unequal

When to Use Which

Just like with equality checks, prefer !== in almost all cases. It prevents the surprising behavior that comes from type coercion.

Use != only when you specifically need loose comparison — which is rare. Most JavaScript developers stick to strict checks for predictable, bug-free code.

Key Takeaway: Use !== to check strict inequality (different type or value). Avoid != unless you intentionally want type coercion — it's the opposite of ===, not of ==.