undefined is a value state; not defined is identifier lookup failure. Strong debugging answers also separate those from TDZ and null, then show the safe check order for missing globals, payload fields, and scope mistakes.
Use this JavaScript interview question to rehearse a quick answer, common mistake, follow-up, and production pitfall.
undefined vs not defined in JavaScriptFrontend interview answer
This JavaScript interview question tests whether you can explain undefined vs not defined in JavaScript: TDZ, typeof, and debug order, connect it to production trade-offs, and handle common follow-up questions.
- undefined vs not defined in JavaScript: TDZ, typeof, and debug order explanation without falling back to memorized docs wording
- Undefined and Referenceerror reasoning, edge cases, and production failure modes
- How you would answer the most likely JavaScript interview follow-up
One-linerundefined means "found variable, value missing". "not defined" means "variable name could not be found".
Real debugging version
A missing API field often becomes undefined. A missing global, typo, or script-load failure often throws "is not defined" instead.
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 nuancetypeof is safe for an undeclared identifier, but it still throws inside TDZ. That is the follow-up distinction many answers skip.
console.log(typeof maybeMissing); // 'undefined' (safe for undeclared names)
{
// console.log(typeof inTdz); // ReferenceError
let inTdz = 1;
}
Real debugging example
A missing property and a missing identifier are different failures. One is data state; the other is name resolution.
const payload = {};
console.log(payload.age); // undefined (missing property value)
console.log(typeof AppConfig); // 'undefined' if the global never loaded
// console.log(AppConfig.timeout); // ReferenceError if AppConfig is undeclared
Fast check order
- If the error literally says "is not defined", check typo, scope, or load order first.
- If a read returns
undefined, inspect assignment timing or object shape. - If
typeofitself throws, you are likely in TDZ rather than dealing with an undeclared global. nullis different again: the value is intentionally empty, not missing by accident.
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 this as one explanation rep, then continue with the JavaScript interview questions cluster or a guided prep path.