Lingua-e
← Errors
JavaScript

X is not a function: What It Means and How to Fix It

Error reference

X is not a function

Language

JavaScript

Severity

High

When it happens

This TypeError is thrown in JavaScript when you attempt to call a value as a function, but that value is not a function.

Potential fixes

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.

Deep dive

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.

Potential fixes

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.

Examples

JavaScript

Code that triggers the error

const config = {
  port: 3000,
};

config.start();

Error output

TypeError: config.start is not a function

Fixed code

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

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

Practice in English

How would you explain a X is not a function to a fellow dev? Choose the right phrase:

"I hit an error...

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