LESSON 06 / 16·2 min readFoundation

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

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

== is loose equality: it may convert values to compatible types before comparing them. === is strict equality: it compares without that conversion. Strict equality usually makes application checks easier to understand because strings, numbers and booleans are not silently treated as the same value.

Important ideas

  • == may convert types: 5 == '5' is true.

  • === does not convert types: 5 === '5' is false.

  • Two separate objects are not equal even if their contents match.

  • null == undefined is true, but null === undefined is false.

  • NaN is not equal to itself with either operator; use Number.isNaN when that is the question.

Comparison:

ExpressionResultReason
5 == '5'trueLoose equality converts types
5 === '5'falseNumber and string differ
null == undefinedtrueSpecial loose-equality rule
{} === {}falseTwo different objects
PAUSE & RECALL

Can you explain it without the notes?

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

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

== is loose equality: it may convert values to compatible types before comparing them. === is strict equality: it compares without that conversion. Strict equality usually makes application checks easier to understand because strings, numbers and booleans are not silently treated as the same value.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Object equality compares identity, not matching properties; switching from == to === does not perform a deep comparison.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: What are null, undefined and NaN?

Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “What is the difference between == and ===?”. Examples are study fragments; framework behavior can depend on your version.