Different Types Of Console Methods You Must Know
Tags: javascript, react, typescript, webdev
Published: 2022-12-21 16:05:43

**You frequently utilised the console.log() method as a JavaScript beginner to show the output of your code. Different kinds of approaches to discover flaws in the code were introduced by JavaScript.**

You can learn console methods on a basic level after reading this tutorial.

## CONSOLE
You may test or verify whether your code is functioning properly or not using the console.

It can be used to gain access to the browser and investigate browser-related issues in your code.

Do not forget that a console is an object that can be accessed by using the dot (.) operator to call methods like log().

## 1.console.log() :
The `console.log()` method outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.

```
console.log('name');          

console.log(1);

console.log(true);

console.log(['a','b','c','d']);

console.log({ one: 1, two: 2, three: 3 });
```
**Output: **

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/slyahm96amivuu889ty7.png)

## 2.console.info()
The `console.info()` is a method in JavaScript that is used to display the important messages to the console.
**Output: **

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1u6v4ldutyvroskrbkr.png)

## 3. console.clear() :
The `console.clear()` method clears the console if the console allows it. A graphical console, like those running on browsers, will allow it; a console displaying on the terminal, like the one running on Node, will not support it, and will have no effect (and no error).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xaby84bw8cnpqhyt0lz.png)

## 4. console.warn() :
If something goes wrong then this method is used to display warning messages to the console.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6od4lrhedtkmtco6vddd.png)

## 5. console.error() :
This method is used to find out errors in the code. `console.error()` method is developed for debugging.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qodigs52d0at1g3rgdn0.png)

## 6.console.assert() :
The `console.assert()` method only displays the message only if the given expression is false.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzta7bqhiz0r83icu24a.png)

## 7.console.count() :
Since we counted the loop's repetitions using the count variable.

The number of times the `console.count()` method is invoked within the application is also counted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kouf2f5ra0326656g6c0.png)

## 8.console.table() :
This method displays data in the form of tables.

The first compulsory parameters passed are in the form of Arrays or Objects, and it requires another parameter as a column(optional parameter).


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/onruq3kimufpq5iljtuy.png)

## 9.console.time() and console.timeEnd() Methods :
The time technique is used to keep track of how long any operation takes to finish a task.

The `console.time()` function is where it starts, and the `console.timeEnd()` method is where it concludes. This is the time frame used in this method's computation of total time.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2hqq5q0hhhv1kj13hxe1.png)

## 10.Grouping Methods :
   **console.group() :**
   This method allows grouping the content logs of the code. It is used to start the group.
   
   **console.groupEnd() :**
    This method is used to end the group.

   **console.groupCollapsed() :**
   This method is used to structure the separate group in a collapsed manner. It's like nesting in the loop.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlagazg5k2765bc57oui.png)


## Conclusion :

You learned about the various console method types in this article. You can employ these techniques for debugging.

Some techniques appear straightforward, yet they can be highly helpful in identifying issues in your code.

These methods enable you to locate the cause of a problem if something goes wrong with your code.