JavaScript — What’s the difference between Null & Undefined?
Null and Undefined have a few subtle differences. Learn the details in two minutes.

Preface
Hey! I’m Brandon. I created codeburst.io and I write JavaScript tutorials and articles to help beginners better understand the inner workings of Web Development. If you have any questions about the article, leave a comment and I’ll get back to you, or find me on twitter @brandonmorelli. Lastly, when you’re ready to really dive into Web Development, Check out the Best Courses for Learning Full Stack Web Development
null !== undefined
Null
Null means an empty or non-existent value. Null is assigned, and explicitly means nothing.
var test1 = null;console.log(test1);
// null
null
is also an object. Interestingly, this was actually an error in the original JavaScript implementation:
console.log(typeof test1);
// object
Undefined
Undefined means a variable has been declared, but the value of that variable has not yet been defined. For example:
var test2;console.log(test2);
// undefined
Unlike null
, undefined is of the type undefined
:
console.log(typeof test2);
// undefined
Here are a two other examples of how you would get an undefined
variable in JavaScript:
- Declare a variable then assign
undefined
to it:
var test = undefined;console.log(test);
// undefined
- Looking up non-existent properties in an object:
var test = {};console.log(test.prop);
// undefined
Summarize it for me, Brandon
Here are the quick facts:
null
is an assigned value. It means nothing.undefined
means a variable has been declared but not defined yet.null
is an object.undefined
is of typeundefined
.null !== undefined
butnull == undefined
.
You did it.
Good work! You can now differentiate between null
and undefined
. I publish a few articles and tutorials each week, please enter your email here if you’d like to be added to my once-weekly email list.
❤ If this post was helpful, please hit the little blue heart! And don’t forget to check out my other recent articles:
- JavaScript: Why does 3 + true = 4? (and 7 other tricky equations)
- And when you’re ready to really dive into Web Development, Check out the 5 Best Courses for Learning Full Stack Web Development