JS-032
Visual JavaScript guide to == vs ===: Understand the difference between == and === in JavaScript
Beginner4 min~4 min read#equality#loose-equality#strict-equality

== vs ===

Similar, but different

Goal

Understand the difference between == and === in JavaScript.

Explanation

  • == checks equality after possible type conversion.
  • === checks both value and type without automatic conversion.
  • Because of this, == can sometimes give unexpected results.
  • For example, 0 == false returns true because JavaScript converts types before comparing.
  • In most cases, it is safer to use ===.

Analogy

== is like a judge who says "they are close enough." === is like a strict judge who checks both appearance and document type.

Code

console.log(0 == false);
console.log(0 === false);

Result: true false

Common mistake

Beginners often think == and === are almost the same. In reality, the difference matters a lot because of automatic type conversion.

Remember

  • == may convert types.
  • === does not convert types.
  • In most cases, use ===.

Quick Quiz

Which operator checks both value and type?

Resources