x is not a function

JavaScript ErrorTypeErrorCommonLast updated: June 28, 2026Tested on:V8 Engine v11.3ECMAScript 2023June 2026

An attempt was made to call a value as a function, but the value is not callable.

x is not a function Quick Fix⏱️ Est. Fix Time: 2–6 minutes

Usually happens because:

  • Variable is a primitive value
  • Typo in method name spelling
  • Callback was not passed

🔍 Quick Checklist:

📊 Where this usually happens (estimated occurrence)

Typo in method names40%
Array method called on non-array30%
Missing callback arguments20%
Import resolver failures10%

What is x is not a function?

The 'x is not a function' TypeError occurs when you attempt to invoke a variable or property as if it were a function (using parenthesis ()), but the variable contains a different type (such as a string, number, object, or undefined) that is not callable.

Common Causes

  • Typo in method names or spelling errors.
  • Reassigning a function variable to a primitive value.
  • Attempting to call array methods on objects that are not arrays.
  • Invoking callback functions that were not passed to the wrapper function.

Common Mistakes

  • Assuming a third-party package exports a default function when it actually exports named bindings.
  • Typoing capitalization on standard utility methods (e.g. calling getelementbyid instead of getElementById).

How to Fix

1Check typeof value === 'function' before calling it.
2Double-check method spelling and match capitalization cases.
3Ensure modules or APIs are successfully imported.
4Provide fallback functions when callbacks are optional.

Framework-Specific Examples

Calling array functions (like map or filter) on elements that are strings or normal objects.

Mismatched Array Methods Example
const data = { names: "John" };
try {
  // Throws TypeError because names is a string, not an array
  data.names.map(n => console.log(n));
} catch (err) {
  console.error(err.message); // data.names.map is not a function
}

Server Configuration Examples

Checking function parameters.

Node.js optional function checks Config
# Handled at code level

Best Practices

  • Use TypeScript to guarantee that callables match signature definitions.
  • Implement callback fallback assertions: `const fn = callback || (() => {})`.

Frequently Asked Questions (FAQ)

Q: What does 'x is not a function' mean?

It means you attempted to call a variable like a function using `()`, but the variable does not contain a callable function.

Q: How do I check if a variable is a function?

Verify using the typeof operator: `if (typeof variable === 'function')`.

Q: Can optional chaining be used on functions?

Yes. You can use the syntax `callback?.()` to invoke the function only if it is defined and callable.

Q: Why does this happen on array map?

Because the variable you are calling `.map()` on is not an array. It could be an object, null, or undefined. Print the variable type using `Array.isArray(variable)`.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error