Learn
JavaScript TypeError: X is not a function
Last updated: August 22, 2026
Fix TypeError: X is not a function in a free online JavaScript compiler. Learn why the value is not callable, how to inspect it, and how to repair the call without rewriting the whole file.
Reproduce the error, then fix itWhat the message actually says
TypeError: X is not a function means JavaScript evaluated an expression and then tried to call it with parentheses. The expression produced a value — a number, a string, an object, null, or undefined — but that value is not callable.
The name in the message is a clue, not a full diagnosis. user.greet is not a function tells you the callee was user.greet. It does not tell you whether greet was never defined, was overwritten, or was invoked too early.
In Code Arena, read Output from the first exception of the latest run. Fix that call before you rewrite the rest of the file. Later errors often cascade from the first bad call.
The value is usually undefined
The most common case is a missing property or a typo. user.greet() throws when greet was never assigned. consle.log throws because console was misspelled. typeof then reports undefined.
The second common case is shadowing. You assigned a string or number to a name that used to hold a function, then called it later. The function is gone; the new value is what gets invoked.
A third case is optional data. API-shaped objects in tutorials sometimes omit a method. You expected a function and received a plain object. Log the object before you call anything on it.
- Check spelling of the function name
- Confirm the object actually has that method
- Log typeof value and the value on the line before the call
- Search for later assignments that overwrite the function
Parentheses in the wrong place
Callbacks bite people: array.map(console.log()) calls console.log immediately and passes its return value (undefined) into map. You wanted array.map(console.log) or a wrapper function.
The same pattern shows up with setTimeout(fn(), 1000). The extra parentheses run the function now. The timer later tries to call whatever fn returned, which is often undefined.
Optional chaining has a similar trap. maybeFn?.() calls if maybeFn exists. maybeFn? without the call is just a value. If you then add () on the wrong expression, you get a TypeError that looks random until you look at the grouping.
A 60-second fix loop
Reproduce the error with the smallest snippet that still throws. In Code Arena that is easy: delete everything that is not required for the crash, then Run.
Log the callee. Decide whether you need to define a function, pass a function reference, or stop calling a non-function. When Output is clean, add back one piece of the original program at a time.
If you are teaching, ask students to read the exception name out loud before they change code. The habit stops the rewrite-from-scratch reflex that hides the real lesson.
Try it in the JavaScript editor
Open the starter snippet and Run it to see TypeError: user.greet is not a function. Add greet as a function and Run again. Then try nums.map(console.log()) and compare the message.
Those two drills cover most “is not a function” reports you will see in homework and interview warm-ups.
FAQ
- What does TypeError: X is not a function mean?
- JavaScript tried to call a value with (). The value exists, but it is not a function — often undefined, a string, a number, or an object.
- How do I find which value is wrong?
- Log typeof value and the value on the line before the call. If you see undefined or object, you called the wrong name or forgot to assign a function.
- Can I try this without installing Node?
- Yes. Open the JavaScript editor on Code Arena, paste the snippet, and press Run. Output shows the TypeError immediately.