- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript null and undefined
JavaScript Type System
JavaScript null and undefined
undefinedmeans a value was never set;nullmeans it was set to nothing on purpose.
Both represent an absence, which is why they are so often confused.
The difference is who caused it: JavaScript, or you.
Example
Example
javascript
let notSet;
const emptied = null;
console.log(notSet);
console.log(emptied);The output is undefined then null.
Which One Appears When
undefined is what JavaScript gives you: an unassigned variable, a missing property, a function with no return.
null is what you assign yourself to say deliberately empty.
