# Solution For Error “TypeError: Console.log(…) Is Not A Function” In JavaScript

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 (;)

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.