undefined is a real value on an existing identifier; not defined indicates identifier resolution failed (ReferenceError). Distinguishing value-state from scope-resolution is key to fast JS debugging.
undefined vs not defined in JavaScript
One-linerundefined means "found variable, value missing". "not defined" means "variable name could not be found".
Case | Declared? | Outcome |
|---|---|---|
| Yes |
|
| No | ReferenceError: nope is not defined |
TDZ access ( | Yes (uninitialized) | ReferenceError |
let a;
console.log(a); // undefined
// console.log(b); // ReferenceError: b is not defined
{
// console.log(c); // ReferenceError (TDZ, not "undeclared")
let c = 1;
}
typeof nuance
console.log(typeof maybeMissing); // 'undefined' (safe for undeclared names)
{
// console.log(typeof inTdz); // ReferenceError
let inTdz = 1;
}
Symptom | Likely cause |
|---|---|
is not defined | Typo, wrong scope, or script/module load-order issue. |
Cannot access X before initialization | TDZ with let/const/class. |
Value is undefined unexpectedly | Missing assignment/data path/property. |
Practical scenario
A feature flag name is misspelled in one module and unset in another. One path throws "not defined", another returns undefined. Distinguishing these quickly saves debugging time.
undefined is an empty seat with a seat number. "not defined" means there is no seat with that number in this hall.
- undefined is data state.
- not defined is scope lookup failure.
- TDZ is a third case: declared but temporarily inaccessible.
Use the relevant interview-question hub first, then move into a concrete study plan before targeted company sets.