What are common sources of undefined in JavaScript?
Declared but unassigned variables, missing function parameters, functions with no return, accessing a non-existent object property, and the result of void 0.
Verify This Answer
Cross-check this information using these trusted sources:
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
