Beginner JavaScript Interview QuestionsBeginnerComparison
JavaScript · Question 9
What is the difference between null and undefined in JavaScript?
Direct answer
undefined usually represents a missing or not-yet-assigned value, while null is an explicit value commonly used to represent an intentional absence.
Both null and undefined are primitive, falsy, and nullish values, but they usually communicate different intent.
- undefined: commonly appears for an uninitialized variable, a missing object property, or a function that returns no explicit value.
- null: is commonly assigned intentionally to represent “no value” or “no object.” Some Web APIs also return null for a missing result.
null == undefined is true because loose equality has a special nullish rule, but null === undefined is false because they are different types.