Lingua-e
JavaScript

What is a X is not a function?

← Errors

This TypeError is thrown in JavaScript when you attempt to call a value as a function, but that value is not a function. The 'X' in the message is the name or expression that was called. It typically means a property that should be a function is undefined, null, or a different type.

Why it happens

  • Calling a method that does not exist on an object (the property is undefined).
  • A variable was reassigned from a function to a non-function value before the call.
  • Forgetting to require or import a module and calling a property on the undefined result.
  • Accidentally overwriting a built-in method such as Array.prototype.map with a non-function value.

Examples

JavaScript

Code that triggers the error

const config = {
  port: 3000,
};

config.start();

Error output

TypeError: config.start is not a function

How to fix it

Log the value before calling it to confirm it is actually a function: console.log(typeof myValue). Check for typos in method names. If the method comes from an external source (API response, configuration), validate its type before calling it.

Fixed code

const config = {
  port: 3000,
  start() {
    console.log(`Server starting on port ${this.port}`);
  },
};

config.start();  // Server starting on port 3000

Related errors

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free