What is a JavaScript console? Explained
Tags: javascript, webdev, programming, beginners
Published: 2022-09-14 11:26:01

In this article, You will learn about the JavaScript Console and types of console methods with examples of how to use them.

## What is a console in JavaScript? 
Console in JavaScript is an object that provides access to the browser's web console. It can be coupled with other approaches to achieve a variety of actions. Which is used for debugging and results logging.


- All modern browsers have a web console for debugging.
- Console is a global object, meaning it is accessible in the browser window's global scope. You can use it as a straight `console` or `window.console`.

All current browsers provide a console that may be accessed through a keyboard shortcut key. To access the browser console:

- In Chrome and other chromium-based browsers, press the **F12 key**.
- For Mozilla Firefox, use the keyboard shortcuts **CTRL + SHIFT + K.**
- In Safari, use the keyboard shortcut keys **Option + ⌘ + C.**

It can also be accessed by right-clicking on a web page and choosing "Inspect" from the menu.



![Console option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jhxegl0e16tg4q86h948.png)

To open the console, click the Console option:


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

## Console Methods
Console in JavaScript has several different methods. Among all the log methods is most commonly used.


### 1. console.log( )
This method is mainly used to log output to the console. We can use any type within log(), such as a string, array, or object.



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

Similarly, `console.info` and `console.error` can be used to display text on the console:



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

### 2. console.clear( )
It's used to clear the console.



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

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

### 3. console.time( ) & console.timeEnd( )
In order to display how many milliseconds a block of code or a function takes to run, use `console.time()` and `console.timeEnd()`:


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

### 4. console.table( )
It allows us to generate a table inside a console. 


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

### 5. console.group( ) & console.groupEnd( )
It is used to move the output to the next level by indenting it:


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

### 6. console.count( )
It is used to count the number of times the function is called using this counting method.


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

### 7. custom console logs.
Users can add styling to the console logs in order to make logs custom.


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

## Wrapping up
Many developers utilise the console to log data in order to see whether or not their code is functioning correctly. It enables the developer to read, edit, and modify JavaScript code while the browser is running.

JavaScript has a console object that can be used to log information to the browser's console.

If you enjoyed this article, then don't forget to give 💚 and If you have any suggestions or tips, feel free to leave a comment or contact me on Twitter at [@ravinwashere](https://twitter.com/ravinwashere). see you later!