Skip to content

Undefined

Easy — everyone uses thisGeneral Dev

ELI5 — The Vibe Check

Undefined in JavaScript means a variable exists but has never been given a value. It is like a labeled empty box — the box is there, but nobody put anything in it. Null is 'empty on purpose'; undefined is 'empty because nobody got around to filling it yet'.

Real Talk

Undefined is a primitive value in JavaScript indicating a variable that has been declared but not yet assigned. It also occurs when accessing non-existent object properties, function parameters not passed by the caller, and functions that return nothing. It is distinct from null (intentional absence). TypeScript can catch many undefined-related bugs at compile time through strict null checks.

Show Me The Code

// How undefined appears:
let x;                    // declared but not assigned
console.log(x);           // undefined

const obj = { name: 'Alice' };
console.log(obj.age);     // undefined — property doesn't exist

function greet(name) {
  console.log(name);      // undefined if called as greet()
}

// Guard against undefined:
const age = obj.age ?? 18; // default if null or undefined

When You'll Hear This

"You're accessing a property that's undefined — check the object shape." / "TypeScript's strict mode catches undefined access before runtime."

Made with passive-aggressive love by manoga.digital. Powered by Claude.