What are common causes of ReferenceError in JavaScript?
Using an undeclared variable, misspelling a variable name, using a variable outside its scope, accessing a let/const in the TDZ, and forgetting to import a module.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in ReferenceError: x is not defined in JavaScript
It means the variable x does not exist in any accessible scope. It was never declared, is misspelled, is out of scope, or was not imported. It is different from undefined, which means the variable exists but has no value.
Because it sounds like 'undefined,' but they are different. undefined is a value for a declared-but-empty variable. 'not defined' is an error meaning the variable does not exist at all.
Use typeof. typeof an undeclared variable returns 'undefined' without throwing. For example: if (typeof someGlobal !== 'undefined') { ... } is safe for feature detection.
Still have questions?
Browse all our FAQs or reach out to our support team
