TypeError: x is not a function
Error message
x is not a function
Quick summary
You used parentheses to call a value, but that value is not a function — it's a number, string, object, or `undefined`.
Why this happens
Property or method name is misspelled (e.g.,
arr.legnth()instead ofarr.length)The value is
undefinedornullbecause a lookup or API call failedA built-in method was overridden or the object is the wrong type
Minimal example
const num = 5;
num();const fn = () => 5;
fn();num is a number, not a function — calling it with () throws a TypeError. Assign a function instead.
How to diagnose
Log the value and its type with
console.log(typeof value)before the callCheck if the function exists on the object with
typeof obj.methodVerify the object is the type you expect it to be
How to fix
Fix the method name to match the real method (e.g.,
length, notlegnth)Ensure the value is actually a function before calling it
Check that the object is the correct type before calling its methods
How to prevent
Use
typeofchecks before calling uncertain functionsUse TypeScript to catch type mismatches at compile time
Related Resources
Related Lessons
- Functions
Learn how JavaScript functions work
Related Practice
- Find the Arrow Function Error
Spot a common syntax error in an arrow function.