What is the difference between null and undefined? Where does each one appear naturally?
Show the explanation
Model answer. Both mean "no value", but they are used differently:
- `undefined` is what JavaScript gives you when something was never set: a declared but unassigned variable, a missing function argument, a missing object property, or a function that returns nothing.
- `null` is a value you assign on purpose to say "intentionally empty", for example clearing a selected item.
let picked; // undefined: never assigned
const user = { manager: null }; // null: we know there is no manager
user.phone; // undefined: property does not existQuirks worth knowing:
typeof undefinedis"undefined", buttypeof nullis"object", a historical bug kept for compatibility.null == undefinedistrue, butnull === undefinedisfalse.- Default parameters apply only for
undefined, notnull:f(null)does not triggerfunction f(x = 5). ??(nullish coalescing) treats both as missing:value ?? 'none'.
Original UniCircle question. Last reviewed 22 Oct 2026.
