What is the difference between null and undefined?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
undefined means a value was never assigned; null means 'intentionally empty' and must be assigned explicitly. They are loosely equal (==) but not strictly equal (===).
Detailed explanation
undefined appears when the language itself has nothing to give you: an uninitialized let variable, a missing object property, an omitted function argument, or a function with no return statement. Its type is 'undefined'. null is a deliberate placeholder written by the developer meaning 'no value on purpose', typed as 'object' due to a historical bug. Practically: prefer letting things be undefined when absent, use null when APIs need an explicit empty signal (e.g., resetting a selected item). Both are falsy and both satisfy x == null, which is why the loose-equality idiom if (x == null) safely covers both cases. Optional chaining (?.) and default values (??) were designed around exactly this pair.
Example
let a;
console.log(a); // undefined
console.log({}.missing); // undefined
function f(x) { return x ?? 'fallback'; }
f(null); // 'fallback'
f(undefined); // 'fallback'
f(0); // 0 — ?? ignores only null/undefinedInterview tip
Anchor the answer in intent: 'undefined = not assigned yet, null = deliberately empty.' Then connect it to modern syntax like ?? and ?. — that lands well.
Common mistakes
- Muddling semantics into a vague 'both mean nothing' answer without intent.
- Forgetting typeof null === 'object' while typeof undefined === 'undefined'.