Difference between == and ===

Learn why strict equality (===) avoids unexpected type coercion in JavaScript.

beginnerFundamentalsjavascriptequalitytype coercion
Published: 11/3/2025
Updated: 11/3/2025

Question

What’s the difference between == and ===?


Answer

  • == performs type coercion before comparison
  • === checks both type and value
console.log(5 == '5'); // true (string converted to number)
console.log(5 === '5'); // false (different types)

Type coercion pitfalls:

console.log(0 == false); // true
console.log('' == false); // true
console.log([] == false); // true

Real-World Example

Always use === in conditions — coercion often leads to hidden bugs.

Quick Practice

Predict:

console.log(null == undefined);
console.log(null === undefined);

Summary

===is safer, predictable, and modern — it’s how professionals compare in JavaScript.

Related Videos
Watch these videos to learn more about this topic
Frequently Asked Questions

Should I ever use == ?

Avoid it. Always use === unless you explicitly need type coercion.


Stay Updated

Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.