TypeError (intermediate value)(...) is not a function in JS

avatar

Borislav Hadzhiev

Tue Oct 19 20212 min read

banner

Photo by Jake Melara

TypeError (intermediate value)(...) is not a function #

The "TypeError: (intermediate value)(...) is not a function" error occurs when we forget to place a semicolon between a function declaration and an immediately invoked function expression. To solve the error, add a semicolon after the closing curly brace of the function declaration.

typeerror intermediate value is not a function

Here's an example of how the error occurs.

index.js
// ⛔️ TypeError: (intermediate value)(...) is not a function const logger = function () { console.log('hi'); } // 👈️ missing semicolon here (function () {})();

To solve the error add a semicolon after the closing curly brace of the function declaration.

index.js
// ✅ Work const logger = function () { console.log('hi'); }; (function () {})();

We got the (intermediate value)(...) is not a function" error because the immediately invoked function expression on the next line got as an argument list for the logger function.

Basically, the logger function got invoked with a function as a parameter and the return value of the logger function got invoked once more causing the error.

If you can't spot where the error occurs, look at the error message in your browser's console or your terminal (if using Node.js).

typeerror intermediate value is not a function

The screenshot above shows that the error occurred in the index.js file on line 21.

Here's another example of how the error occurs.

index.js
const obj = { getNum() { return 5; }, sum(a) { // ⛔️ TypeError: (intermediate value).getNum is not a function return a + super.getNum(); }, }; console.log(obj.sum(10));

In this example we have a TypeError because we use the super() keyword instead of using this.

index.js
const obj = { getNum() { return 5; }, sum(a) { // ✅ Works return a + this.getNum(); }, }; console.log(obj.sum(10));
The value is called an "intermediate value" because calling the getNum function does not produce the final result of the expression, we later add the value stored in the a variable to get the final result.

On the line the error occurred, make sure that you only invoke valid functions.

Having an extra set of parenthesis, e.g. sum()() might also cause the error.

Further Reading #

Use the search field on my Home Page to filter through my more than 1,000 articles.