What does undefined is not a function mean in JavaScript?

Updated October 2026 · How we answer

Short answerIt means you tried to call something as a function, but it's actually undefined. This often happens when a function name is misspelled, a method doesn't exist, or a variable is not initialized.

Common causes

This error occurs when you use parentheses to call a value that is not a function. For example, let x; x(); throws it because x is undefined. Similarly, if you misspell a method name like array.lenght(), you'll get it because lenght is undefined.

Another frequent cause is trying to call a method on an object that doesn't have it, or when a library fails to load. In older browsers, some methods might not be supported, leading to this error.

How to fix it

Check the spelling of the function or method name. Use console.log() to print the value before calling it to see if it's undefined. Ensure that any external libraries are loaded before you use their functions.

If you're using a variable that should hold a function, make sure it's assigned. For example, if you define a function with function myFunc() {} or const myFunc = () => {}, then call it. If the function is part of an object, verify the object exists and has that property.

In modern JavaScript, you can use optional chaining (?.) to avoid errors when calling a method that might not exist: obj.method?.(). However, this only prevents the error; you still need to ensure the method exists if you expect it to run.

  • Check for typos in function or method names.
  • Use console.log() to inspect the value before calling it.
  • Ensure libraries are loaded before use.
  • Verify that variables holding functions are assigned.
  • Consider using optional chaining (?.) for potentially undefined methods.

Examples

If you have const arr = [1,2,3]; arr.forEach(...) works, but arr.foreach(...) throws because foreach is not a function (it's forEach with a capital E). If you have let obj = {}; obj.method(); throws because method is undefined.

If you're using a framework like React, this error can occur if you forget to bind a method or if you call a hook conditionally. Always follow the framework's rules for defining and calling functions.

Common mistakes

  • Misspelling method names, like using 'foreach' instead of 'forEach'.
  • Assuming a variable is a function without checking its type.
  • Forgetting to load a library or script before using its functions.
From our shopsCASEONYX: Dark-luxe tough phone cases.