What is the difference between `null` and `undefined`?

Beginner

Answer

  • undefined: Variable has been declared but not assigned a value, or function parameter not provided
  • null: Intentional assignment representing "no value" or "empty"
let a; // undefined
let b = null; // null
typeof undefined; // "undefined"
typeof null;      // "object" (legacy quirk)