What is the difference between == and === in JavaScript?

Answer

== (loose equality) compares values after performing type coercion — JavaScript converts both sides to a common type before comparing. This leads to surprising results: "5" == 5 is true, 0 == false is true, null == undefined is true, "" == 0 is true. === (strict equality) compares both value AND type without any coercion: "5" === 5 is false. Always use === in production code to avoid coercion bugs. The only common exception where == is acceptable is checking for both null and undefined simultaneously: value == null returns true for both null and undefined. The non-equality counterparts are != and !==.