← Blog

Day 6 of 21 Days of Javascript

Today I started looking at how objects work in JS. The really cool thing about using AI for learning (and not for answers) is that you can use it to help you create cheat sheets to help you remember key ideas. Here’s one I asked Chat GPT-5 to create for me on how equality is dealt with across objects.


JavaScript == vs === Cheat Sheet

Key idea:

  • ===Strict equality: same value and same type.
  • ==Loose equality: converts (coerces) types before comparing.
  • For objects (including arrays), both check identity — whether two variables point to the exact same object in memory.

📊 Examples

Expression

== result

=== result

Why?

5 == "5"

✅ true

❌ false

== converts string → number before comparing

0 == false

✅ true

❌ false

== converts false → 0

null == undefined

✅ true

❌ false

== treats them as equal, === doesn’t

[] == ""

✅ true

❌ false

[]"" when coerced

[1] == 1

✅ true

❌ false

[1]"1"1

{} == {}

❌ false

❌ false

Different object references

obj1 == obj2 (same object), where we have declared:
let obj1 == {…};<br>let obj2 == obj1;

✅ true

✅ true

Both point to same object in memory


🧠 Rules of Thumb

  • Prefer ===, it avoids weird coercion surprises.
  • Use == only if you really want type conversion (rare).
  • Remember: two separate object or array literals are never equal, even if they have the same contents.