JavaScript raises `TypeError: X is not a function` when something is invoked like a callable but the value is actually a string, number, object, undefined reference, or another non-callable value.
Focus on callability, function references, object methods, array methods, and the places where a variable gets reassigned or a property lookup returns the wrong value.
A strong understanding of not_a_function should include the exact value type being called, the reason it is not callable, and the difference between a typo, a missing method, and an overwritten function.
JavaScript is not a function Callable Values Typos and Method Lookup should be studied as a practical JavaScript lesson, not as a label. Start by naming the input, the rule that changes the input, and the result a learner should be able to predict after reading the page.
In the javascript > errors > not-a-function page, the notes should connect the definition with a working scenario, a mistake that beginners actually make, and the exact check that proves the fix. That makes the topic useful for coding, debugging, and interview revision.
The error TypeError: X is not a function occurs when you try to call something as a function that isn't actually a function. This happens when the variable is undefined, null, or a different data type.
// [wrong] Problem
let myFunc = 'not a function';
myFunc(); // TypeError: myFunc is not a function
// [ok] Solution 1: Check if it's a function
if (typeof myFunc === 'function') {
myFunc();
}
// [ok] Solution 2: Define the function properly
function myFunc() {
console.log('I am a function');
}
myFunc(); // Works!
Trying to call a variable that contains a non-function value.
Calling a function with a typo in its name.
Trying to call an object property that's not a function.
Calling array methods on variables that aren't arrays.
Accidentally overwriting a function with another value.
// Variable is a string
let calculate = 'sum';
calculate(5, 10); // TypeError: calculate is not a function
// Variable is a number
let process = 42;
process(); // TypeError: process is not a function
// Variable is undefined
let handler;
handler(); // TypeError: handler is not a function
// Check type before calling
let calculate = 'sum';
if (typeof calculate === 'function') {
calculate(5, 10);
} else {
console.error('calculate is not a function');
}
// Define as a function
let calculate = function(a, b) {
return a + b;
};
calculate(5, 10); // 15
// Or use arrow function
let calculate = (a, b) => a + b;
calculate(5, 10); // 15
function calculateSum(a, b) {
return a + b;
}
// Typo: calculateSun instead of calculateSum
calculateSun(5, 10); // TypeError: calculateSun is not a function
// Case sensitivity
CalculateSum(5, 10); // TypeError: CalculateSum is not a function
// Fix the typo
function calculateSum(a, b) {
return a + b;
}
calculateSum(5, 10); // 15 - Works!
// Use IDE autocomplete to avoid typos
// Use ESLint to catch undefined functions
const user = {
name: 'John',
age: 30
};
user.greet(); // TypeError: user.greet is not a function
// Or accessing wrong property
const calculator = {
sum: function(a, b) { return a + b; }
};
calculator.add(5, 10); // TypeError: calculator.add is not a function
// Add the method to the object
const user = {
name: 'John',
age: 30,
greet: function() {
return `Hello, I'm ${this.name}`;
}
};
user.greet(); // "Hello, I'm John"
// Or use correct property name
const calculator = {
sum: function(a, b) { return a + b; }
};
calculator.sum(5, 10); // 15
// Check if method exists
if (typeof user.greet === 'function') {
user.greet();
}
let users = null;
users.map(u => u.name); // TypeError: users.map is not a function
// Or undefined
let items;
items.filter(i => i.active); // TypeError: items.filter is not a function
// Or wrong type
let data = 'not an array';
data.forEach(item => console.log(item)); // TypeError!
// Initialize as array
let users = [];
users.map(u => u.name); // Works (returns [])
// Check if array before using
let users = null;
if (Array.isArray(users)) {
users.map(u => u.name);
}
// Use optional chaining with default
let users = null;
const names = users?.map(u => u.name) || [];
// Or nullish coalescing
let users = null;
(users ?? []).map(u => u.name);
function calculate(a, b) {
return a + b;
}
// Accidentally overwrite
calculate = 42;
calculate(5, 10); // TypeError: calculate is not a function
// Or in loop
for (let calculate = 0; calculate < 10; calculate++) {
// calculate is now a number
}
calculate(5, 10); // TypeError!
// Use const to prevent reassignment
const calculate = function(a, b) {
return a + b;
};
// calculate = 42; // TypeError: Assignment to constant variable
// Use different variable names
function calculate(a, b) {
return a + b;
}
for (let i = 0; i < 10; i++) {
// Use 'i' instead of 'calculate'
}
calculate(5, 10); // Works!
JavaScript is not a function Callable Values Typos and Method Lookup matters in JavaScript because it changes how a program is written, tested, or debugged. The page should explain the normal flow first: what the developer writes, what the runtime or platform does, and what result should appear.
When teaching JavaScript is not a function Callable Values Typos and Method Lookup, avoid stopping at syntax. Show the surrounding decision: why this feature is chosen, what problem it removes, and what would become harder if the feature were not used.
The strongest notes for JavaScript is not a function Callable Values Typos and Method Lookup explain where the idea stops working. Add cases for missing input, wrong order, incompatible types, duplicate values, empty collections, failed requests, or configuration mismatch when those cases fit the lesson.
Readers should leave the page knowing how to inspect a bad result. For JavaScript is not a function Callable Values Typos and Method Lookup, that means checking the relevant value, state, dependency, selector, query, route, class, or runtime message before changing code randomly.
class JavaScriptisnotafunctionCallableValuesTyposandMethodLookupReview {
public static void main(String[] args) {
String state = "ready";
System.out.println("JavaScript is not a function Callable Values Typos and Method Lookup: " + state);
}
}
String value = null;
if (value == null) {
System.out.println("JavaScript is not a function Callable Values Typos and Method Lookup: handle the missing value before continuing");
}
Learning `not_a_function` only as a message instead of tracing the value being called.
Pair the error message with one working callable and one failing value type.
Calling a value before checking whether it actually holds a function reference.
Trace the variable assignment, the property lookup, and the actual call expression.
Testing only the happy path where the value is already callable.
Also test the missing method, overwritten function, and wrong-type cases that trigger the TypeError.
Memorizing JavaScript is not a function Callable Values Typos and Method Lookup without the situation where it is useful.
Connect JavaScript is not a function Callable Values Typos and Method Lookup to a concrete JavaScript task.
This error occurs when you try to call something as a function that isn't actually a function. Common causes include typos in function names, calling undefined variables, using wrong data types, or accidentally overwriting functions.
Check if the variable is actually a function using typeof, fix any typos in function names, ensure the function is defined before calling it, and verify you're calling the correct property name.
This happens when calling .map() on a variable that is not an array. The variable might be null, undefined, or a different data type. Check with Array.isArray() or use optional chaining.
Use typeof: if (typeof myVar === 'function') { myVar(); }. This checks if the variable is a function before calling it.
Yes, using const for function declarations prevents accidental reassignment. If you try to overwrite a const function, you'll get a different error that's easier to debug.
Explore 500+ free tutorials across 20+ languages and frameworks.