Ask any question about JavaScript here... and get an instant response.
Post this Question & Answer:
What is the difference between null and undefined in JavaScript?
Asked on Feb 19, 2026
Answer
In JavaScript, "null" represents an intentional absence of any object value, while "undefined" indicates a variable that has been declared but not assigned a value. Here's a simple example to illustrate the difference:
// Example of undefined
let a;
console.log(a); // Output: undefined
// Example of null
let b = null;
console.log(b); // Output: nullAdditional Comment:
✅ Answered with JavaScript best practices.- "undefined" is the default value for variables that are declared but not initialized.
- "null" is an assignment value that can be used to represent no value or an empty object reference.
- Both "null" and "undefined" are falsy values, meaning they evaluate to false in a boolean context.
- Use "null" when you want to explicitly indicate that a variable should be empty.
Recommended Links:
