Side-by-side comparison of ReferenceError and TypeError — understand the differences, causes, and fixes.
ReferenceErrorA reference was made to a variable that does not exist in the current scope.
You tried to use a variable that has not been declared, is not in scope, or was accessed before its declaration (temporal dead zone). This can also happen with misspelled variable names.
Declare the variable before using it with let, const, or var. Check for typos in variable names. Ensure the variable is in scope where you are accessing it. Import missing modules.
TypeErrorA value is not of the expected type. This is the most common JavaScript error, occurring when an operation encounters a value of the wrong type.
You attempted to use a value in a way that is incompatible with its type. Common examples include calling a non-function, accessing properties of null/undefined, or passing the wrong argument type to a built-in method.
Check the variable's actual type using typeof or console.log before the failing operation. Add null/undefined checks. Use optional chaining (?.) for potentially null values. Verify function arguments match expected types.