Facebook Pixel
JavaScript: not defined vs ReferenceError vs TypeError

What is the difference between ReferenceError and TypeError in JavaScript?

The answer

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.

More FAQs in JavaScript: not defined vs ReferenceError vs TypeError

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.

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

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.