Operators, Coercion and Equality

The rules behind every expression you write: what each operator does, the exact conversions JavaScript performs when types do not match, why == and === disagree, and how truthiness plus the nullish operators decide which default a value gets.

What you will be able to do

  • Read any expression correctly using precedence and associativity
  • Explain results like 1 + "1", [] + {} and true + true step by step
  • Choose between ===, ==, Object.is and a hand-written deepEqual
  • List the eight falsy values and say what is deliberately not on the list
  • Pick ?? over || whenever 0, '' or false is a legitimate value

Lessons

  1. The Operator Tour — An operator is a function with punctuation for a name, and precedence decides who gets the operands. (11 min)
  2. Type Coercion — When an operator needs a type it does not have, JavaScript runs a fixed conversion recipe. Learn the recipe and the surprises disappear. (13 min)
  3. Equality — === asks "same type and same value". == asks the same question after converting, which is why it needs a rulebook. (11 min)
  4. Truthiness and Defaults — Eight values are falsy. Everything else is truthy, including the empty containers people expect to be falsy. (12 min)