undefined is a property of the global object, not a reserved keyword. In modern JavaScript it is non-writable, so you cannot reassign it, but in old engines you could. Avoid relying on it being a keyword.
undefined vs not defined in JavaScript
Is undefined a keyword or an identifier in JavaScript?
The answer
More FAQs in undefined vs not defined in JavaScript
undefined is a value assigned to a declared variable that has no value yet. not defined is a ReferenceError thrown when a variable does not exist in any accessible scope.
Because z was never declared, so it does not exist in any scope. The error message 'not defined' means the variable is missing entirely, which is different from undefined which means the variable exists but has no value.
Use typeof. typeof an undeclared variable returns 'undefined' without throwing a ReferenceError. This is the safe way to check for globals or optional APIs.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.