undefined
A free lesson from Swipe Coding · JavaScript, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
undefined is the value JavaScript automatically gives to a variable that has been declared but not yet assigned a value. It means "nothing has been put here yet" — and unlike null, you rarely assign it yourself.
let score; console.log(score); // undefined
undefined also shows up automatically in other places — for example, when you access an object property that doesn't exist, or call a function that doesn't explicitly return anything.
const user = { name: 'Ada' };
console.log(user.age); // undefinedThe key difference: undefined means a value was never assigned — it's JavaScript's own default for "empty." null means a developer deliberately set "no value" on purpose. Think of undefined as "empty by default" and null as "emptied intentionally."
let a; let b = null; console.log(a); // undefined - never assigned console.log(b); // null - deliberately set to "nothing"
A variable that has been declared but never given a value automatically holds ____.
What is the key difference between null and undefined?
Accessing a property that doesn't exist on an object returns undefined rather than causing an error.
Keep your streak going in Swipe Coding
Swipe through every level of JavaScript on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →