Skip to main content
← JavaScript Lesson 1 / 5

Types & Coercion

JavaScript has two ways to ask "are these equal?". === is strict — same type AND same value. == is loose — it quietly converts one side to match the other, which causes some famous surprises.

Left value

Right value

Operator

Pick two values and an operator. Watch the right panel show, step by step, what JavaScript actually does before answering.

Remember

  • === compares type AND value (no conversion).
  • == converts first, then compares — surprises live here.
  • There are exactly 7 falsy values; everything else is truthy.
  • When in doubt, prefer ===.

The two values

0
typeof "number"
""
typeof "string"

What JavaScript does

  1. 0 == ""
    starting comparison
  2. different types (number vs string) → convert both to number
  3. Number(0) == Number("")
    becomes 0 == 0
  4. 0 == 0 → true
    result

Result

true

Truthy or falsy?

0 falsy 1 truthy "" falsy "0" truthy "1" truthy false falsy true truthy null falsy undefined falsy [] truthy NaN falsy

The 7 falsy values: false · 0 · -0 · "" · null · undefined · NaN. Everything else (including [] and "0") is truthy.