← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

== vs === — Differences

== compares values after type coercion; === compares both value AND type, with no coercion.

0 == '0';     // true  — string coerced to number
0 === '0';    // false — different types
null == undefined;  // true
null === undefined; // false
NaN === NaN;  // false! (use Number.isNaN instead)
  • == triggers type coercion using complex, hard-to-memorize rules
  • === is strict equality — always prefer it in new code
  • Object.is() handles a few extra edge cases like NaN and -0