"TypeError" in JavaScript — What It Means and How to Fix It
What the JavaScript error "TypeError" means and how to fix it.
Published October 29, 2026
TypeError is thrown when a value is not of the expected type, such as calling something that is not a function or reading a property of null.
What it means and why it happens
Typical causes: undefined variables, wrong object shapes, missing return values or calling methods on the wrong type.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
TypeError: undefined is not a function
Practical examples
Code that triggers it
const user = undefined
user.name()The fix
const user = getUser()
if (typeof user?.name === 'function') user.name()Debug the type
console.log(typeof x, x)Common mistakes
- Assuming API data always has the expected shape.
- Forgetting return in functions.
- Calling a method on a promise instead of its result.
Key takeaways
- TypeError: TypeError is thrown when a value is not of the expected type, such as calling something that is not a function or reading a property of null.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
TypeError vs ReferenceError?
ReferenceError: name not defined; TypeError: defined but wrong type.
How do I find which line caused TypeError?
The error message and stack trace show the file and line; start there and work backwards.