Error Reference › JavaScript
JavaScript

X is not a function

You called something as a function, but it isn't one.

What it looks like

Uncaught TypeError: user.getName is not a function
    at showProfile (profile.js:12:24)

What does "X is not a function" mean?

Thrown when code calls something with () that is not a function — undefined, a string, an object or a number. The message names the expression that was called, which is the fastest clue to what went wrong.

What causes "X is not a function"?

  • A typo in the method name.
  • The value is undefined or the wrong type.
  • An import is missing / default-vs-named mismatch.
  • Calling a method before the object is ready.

How do I confirm the cause?

  1. Log typeof and the value of the thing being called (console.log(typeof user.getName, user.getName)).
  2. Check the import: a default export imported with braces, or a named export without them, gives undefined.
  3. Check whether a plain JSON object is being used where a class instance with methods was expected.

How do I fix "X is not a function"?

  • Check the spelling and that the method exists on that object.
  • console.log the value to see what it actually is.
  • Verify the import (default vs named export).

How do I stop it happening again?

  • Use TypeScript or JSDoc types so calls to missing methods are caught before they run.
  • Keep import styles consistent — pick default or named exports per module and stick to it.
Got a different error? Paste it into the Explain This Error tool → Identifies the family and the fix — runs locally, nothing uploaded.

Related errors