Last modified: Apr 28, 2026 By Alexander Williams
TypeError: Is Not a Function Fix Guide
Seeing a TypeError: is not a function message can stop your code cold. This error is common in both Python and JavaScript. It means you tried to call something as a function, but it isn't one.
Don't worry. This guide explains why it happens. You'll learn clear, practical fixes. We'll use short examples and simple explanations.
What Does "Is Not a Function" Mean?
In programming, a function is a block of code that performs a specific task. To run it, you use parentheses (). When you use parentheses on a variable that is not a function, the interpreter throws this error.
The error tells you: "You tried to execute this thing, but it's not callable." It's a type mismatch. The variable holds a number, string, object, or undefined value, not a function.
Understanding this is the first step to fixing it. Always check what type your variable is before calling it.
Common Causes in JavaScript
JavaScript is dynamically typed. This flexibility can lead to this error. Here are the most frequent causes.
1. Misspelled Function Name
A simple typo can cause this. You might write myFuncton() instead of myFunction(). JavaScript looks for the misspelled name. It finds nothing or a different variable.
// Example: Misspelling
function greet() {
return "Hello!";
}
// Typo: "greet" is misspelled as "greet"
console.log(greet()); // Works fine
// Typo: "greet" misspelled as "gret"
console.log(gret()); // TypeError: gret is not a function
// Output
Hello!
TypeError: gret is not a function
Fix: Double-check your spelling. Use an editor with autocomplete. This prevents simple typos.
2. Calling a Method on the Wrong Object
Methods are functions attached to objects. If you call a method that doesn't exist on that object, you get this error. For example, arrays have .map(), but numbers do not.
// Example: Wrong object
let myNumber = 42;
// Numbers don't have a map method
myNumber.map(x => x * 2); // TypeError: myNumber.map is not a function
// Output
TypeError: myNumber.map is not a function
Fix: Ensure the object has the method you want. Check the documentation. Use console.log(typeof myNumber) to see the type.
3. Function Not Yet Defined
JavaScript hoists function declarations, but not function expressions. If you use a function expression before defining it, you get this error.
// Example: Function expression not hoisted
console.log(sayHi()); // TypeError: sayHi is not a function
var sayHi = function() {
return "Hi!";
};
// Output
TypeError: sayHi is not a function
Fix: Use function declarations (which are hoisted) or move your function expression before the call.
Common Causes in Python
Python also throws a similar error: TypeError: 'int' object is not callable. The logic is the same. You tried to call something that isn't a function.
1. Overwriting a Built-in Function
You might accidentally assign a value to a name that is a built-in function. For example, print or str. After that, you can't use the original function.
# Example: Overwriting print
print = 10 # Now 'print' is an integer, not a function
print("Hello") # TypeError: 'int' object is not callable
# Output
TypeError: 'int' object is not callable
Fix: Avoid using built-in names for your variables. Use descriptive names like my_print or output_value.
2. Using Parentheses on a Variable by Mistake
Sometimes you add extra parentheses by accident. This is common when chaining operations. Python tries to call the result as a function.
# Example: Accidental parentheses
length = len("hello") # This is correct
# Typo: extra parentheses
print(length()) # TypeError: 'int' object is not callable
# Output
TypeError: 'int' object is not callable
Fix: Review your code for stray parentheses. Use a linter to catch these errors.
3. Confusing Tuples and Functions
In Python, a tuple is defined with commas, not just parentheses. A single value in parentheses is just a value. Adding a comma after it creates a tuple. This can cause confusion.
# Example: Tuple vs function
my_tuple = (5,) # This is a tuple
print(my_tuple()) # TypeError: 'tuple' object is not callable
# Output
TypeError: 'tuple' object is not callable
Fix: Remember that parentheses alone don't create a tuple. You need a comma. Use type() to check your variable.
How to Debug This Error
Debugging is a systematic process. Follow these steps to find the root cause.
Step 1: Read the error message carefully. It often tells you the variable name. Look at the line number.
Step 2: Check the variable type. Use typeof in JavaScript or type() in Python. Print it to the console.
Step 3: Verify the variable is defined. Ensure you haven't misspelled it. Check if it's in scope.
Step 4: Look for overwritten names. Search your code for assignments to built-in function names.
Step 5: Use a debugger. Set a breakpoint. Step through your code. Watch the variables change.
For more on handling data types, check out our Python Character Encoding Guide for Beginners. It helps with string-related errors.
Preventive Measures
Prevention is better than fixing. Here are habits to avoid this error.
Use meaningful variable names. Avoid single letters. This reduces confusion with built-in functions.
Adopt a consistent coding style. Use linters and formatters. They catch simple mistakes.
Write unit tests. Tests check your functions. They reveal errors early.
Learn your language's data types. Understand what each type can do. This prevents method misuse.
For a deeper dive into Python data handling, read our Python Character Encoding Guide for Beginners. It's a great resource for beginners.
Conclusion
The TypeError: is not a function error is frustrating but fixable. It always means you tried to call a non-function. The causes are simple: misspellings, wrong objects, or overwritten names.
Now you know how to debug it. Check the variable type. Verify the name. Use the right object. With practice, you'll spot these errors instantly.
Keep coding. Keep learning. Every error is a step toward mastery. For more tips, revisit our Python Character Encoding Guide for Beginners.