It is the message in a ReferenceError. 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.
JavaScript: not defined vs ReferenceError vs TypeError
What does 'x is not defined' mean in JavaScript?
The answer
More FAQs in JavaScript: not defined vs ReferenceError vs TypeError
ReferenceError is thrown when a variable does not exist or is in the TDZ. TypeError is thrown when a value is the wrong type for the operation, like calling a non-function or reading a property of null or undefined.
Because the var is hoisted with undefined, so the variable exists (no ReferenceError). But undefined() throws TypeError: x is not a function, because the value is not callable.
An error thrown during parsing, before any code runs. Malformed code like const x = ; causes it. The entire script or module does not execute when there is a SyntaxError.
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.