The “TypeError: console.log(…) is not a function” in JavaScript is standard error, but fixing it is not too difficult. Here are some examples and how to fix them.
Why does the TypeError: console.log(…) is not a function in JavaScript happen?
There are many reasons for the TypeError console.log(…) is not a function in JavaScript, but it is common in the following cases:
- Use Immediately Invoked Function Expression (IIFE) on the same line as console.log() without using a separator (;).
- Declare a console variable with a different value.
The error message occurs as follows:
Uncaught TypeError: console.log(...) is not a function
How to fix this error?
Use (IIFE) on the same line as console.log() without using a separator (;)
To learn more about IIFE, you can visit the MDN docs.
Example:
console.log("Hello LearnShareIT")(() => "Hello World!")();
Output:
Uncaught TypeError: console.log(...) is not a function
The above example shows that after the program loads the console.log() sentence, the program will output the string “Hello LearnShareIT” to the program error message here is thrown when the error is thrown when forgetting the sign to separate the two above codes. Same line when this program will misinterpret the purpose and throw an error.
To fix it, I would do it like this:
console.log("Hello LearnShareIT");(() => console.log("Hello World!"))();
In the above example, to fix the error, I just need to add a sign (;) after the console.log() statement, and our program will usually work.
To avoid the above error field, we pay attention to the mark (;) after the console.log() statement.
Declare a console variable with a different value
Some people often declare the console variable with a different value. Then the program will understand that console is a newly created variable with a specific value.
Example:
const console = 'Demo';
console.log("Hello LearnShareIT");
Output:
Uncaught TypeError: console.log is not a function
The example shows that the console variable we created is a string with the value “Demo” when we call it and call the log function, the program will not understand and throw an error.
To fix this, try calling console.log() through the window object in your browser. I do it like this:
const console = 'Demo';
window.console.log("Hello LearnShareIT");
Output:
Hello LearnShareIT
In the above example, I used your browser’s window object to call the console object and then called the log() method to output the string “LearnShareIT” to the console.
Summary
In this article, I showed you how to fix the TypeError: console.log(…) is not a function in JavaScript. Try reading this article and following along. It will help you to remember and understand the above ways. Hope this article helps you and your program. Good luck.
Maybe you are interested:
- “TypeError: appendChild is not a function” in JavaScript
- “TypeError: Failed to fetch and CORS” in JavaScript
- “TypeError: toISOString is not a function” in JavaScript

My name is Tom Joseph, and I work as a software engineer. I enjoy programming and passing on my experience. C, C++, JAVA, and Python are my strong programming languages that I can share with everyone. In addition, I have also developed projects using Javascript, html, css.
Job: Developer
Name of the university: UTC
Programming Languages: C, C++, Javascript, JAVA, python, html, css