What is the difference between undefined and 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.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in undefined vs not defined in JavaScript
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.
Declared but unassigned variables, missing function parameters, functions with no return, accessing a non-existent object property, and the result of void 0.
Still have questions?
Browse all our FAQs or reach out to our support team
