Chapter III · Data Types

Undefined

Undefined is a primitive type indicating the absence of an assigned value or uninitialized state.

01 What is Undefined?

The Undefined type has exactly one value: undefined. When a variable is declared without an assignment, or a function returns nothing, JavaScript automatically assigns undefined.

It represents the state of a variable or property that has been declared but has not yet been pointed to a valid value.

02 Simple Example

Observing undefined in uninitialized variables and missing property lookups.

undefined.js
let user;
console.log(user); // undefined

const obj = {};
console.log(obj.age); // undefined

Accessing unassigned variables or non-existent object keys defaults gracefully to undefined.

03 How It Works

During variable creation and memory allocation phases, engines initialize variable slots with undefined until explicit assignment occurs.

score identifier 10 value in memory binds to let score = 10; — the name and the value are linked, not fused.

Uninitialized identifiers point to the primitive undefined value by default.

04 Step-by-Step

  1. A variable is declared without an initial value.

  2. The engine binds the identifier to the primitive undefined.

  3. Accessing the variable evaluates to undefined.

05 Mental Model

"An empty parking space with a sign that says 'Reserved, but car has not arrived yet.'"

The spot exists, but nothing occupies it at the moment.

06 Interview Questions

Q: What's the difference between a variable being undefined and not being declared at all?

An undeclared variable throws a ReferenceError when accessed; a declared-but-unassigned variable simply evaluates to undefined.

Q: Can you reassign undefined itself?

In modern engines, undefined is a non-writable global property in most scopes, though it's still best practice never to assign to it directly — use it only as a value to check against.

Key Takeaway

Undefined is the default primitive value assigned to uninitialized variables and missing properties in JavaScript.

Related Concepts