JavaScriptEasy
What's the difference between a JavaScript variable that is: null, undefined or undeclared?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
| Trait | null | undefined | Undeclared |
|---|---|---|---|
| Meaning | Explicitly set by the developer to indicate that a variable has no value | Variable has been declared but not assigned a value | Variable has not been declared at all |
Type (via typeof operator) | 'object' | 'undefined' | 'undefined' |
| Equality Comparison | null == undefined is true | undefined == null is true | Throws a ReferenceError |
Read the detailed answer on GreatFrontEnd which allows progress tracking, contains more code samples, and useful resources.
