
JavaScriptWeb DevelopmentTutorialProgramming Concepts
Null & Undefined
1 min read
Undefined
Undefined means "a value hasn't been assigned yet." Think of it as an empty spot in memory that exists but hasn't been filled with anything.
It occurs when:
- You declare a variable but don't assign it a value
- You try to access an object property that doesn't exist
- A function doesn't explicitly return anything
- You have a function parameter that wasn't provided
Undefined
let dog; // declared but not initialized - value is undefined
console.log(dog); // undefined
function bark() {
// no return statement
}
console.log(bark()); // undefined
const pet = {};
console.log(pet.name); // undefined (this property doesn't exist)Null
Null means "intentionally empty or nothing." It's a deliberate assignment to represent "no value" or "empty value."
Unlike undefined, null is always explicitly assigned:
not defined
let cat = null; // I deliberately set this to "nothing" for nowKey Differences to Remember
Think of it like this:
- Undefined is like an empty shelf that exists but has nothing on it yet (JavaScript assigns this automatically)
- Null is like putting a box labeled "EMPTY" on the shelf (you have to put it there yourself)
More technically:
typeof undefinedis "undefined"typeof nullis "object" (this is actually a historical bug in JavaScript!)null == undefinedis true (loose equality)null === undefinedis false (strict equality)
Loading image...

Share this article
Enjoyed it?
Let's Create Something Amazing Together!
Whether you have a project in mind or just want to connect, I'm always excited to collaborate and bring ideas to life.
Continue the Journey
Thanks for taking the time to explore my work! Let's connect and create something amazing together.