
Null & Undefined
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
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:
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)

Browse More Blogs

A Developer's Guide to Building AI Agents with the Model Context Protocol (MCP)
Go beyond chatbots. Learn how to use the Model Context Protocol (MCP) to build powerful, real-world AI agents that can automate workflows, assist in coding, man

A Freelance Project for an Enterprise
Enterprise freelance project case study: business web development, client collaboration, and delivery.

Foodah
Case study of Foodah - a modern food delivery app showcasing frontend development and UX design.
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.