undefined vs not defined in JavaScript

HighIntermediateJavascript
Quick Answer

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.

Answer

One-liner

undefined means "found variable, value missing". "not defined" means "variable name could not be found".

Case

Declared?

Outcome

let x; console.log(x)

Yes

undefined

console.log(nope)

No

ReferenceError: nope is not defined

TDZ access (let/const before line)

Yes (uninitialized)

ReferenceError

"Not defined" and TDZ both throw, but for different reasons.
JAVASCRIPT
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

JAVASCRIPT
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.

Use error text to jump directly to root cause.

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.

Still so complicated?

undefined is an empty seat with a seat number. "not defined" means there is no seat with that number in this hall.

Summary
      • undefined is data state.
      • not defined is scope lookup failure.
      • TDZ is a third case: declared but temporarily inaccessible.
Similar questions
Guides
Preparing for interviews?

Use the relevant interview-question hub first, then move into a concrete study plan before targeted company sets.