AceDevHub
Beginner JavaScript Interview QuestionsBeginnerComparison

JavaScript · Question 12

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

Direct answer

== performs abstract equality and may coerce operand types, while === performs strict equality without type coercion.

Strict equality (===) compares without converting values to another type. Loose equality (==) follows coercion rules before or during comparison.

Examples: 42 == '42' is true, while 42 === '42' is false. Also, null == undefined is true but their strict equality is false.

  • Use === as the default because its behavior is easier to reason about.
  • Know == because interview questions often test its coercion rules and legacy code may use it.
  • Object equality with either operator normally compares object identity, not deep content.