Why does calling a var function expression early throw TypeError not ReferenceError?
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.
Verify This Answer
Cross-check this information using these trusted sources:
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.
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.
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.
Still have questions?
Browse all our FAQs or reach out to our support team
