# What is a console.log in JavaScript?

The **console.log()** method is mainly used for debugging in **JavaScript**. It outputs a message to the web console. All modern web browsers provides support for it. 

## 1. Strings
You can write anything to the web console by passing it as a string. For example,

![console.log string example](https://cdn.hashnode.com/res/hashnode/image/upload/v1646039093729/r1KBcKolJ.png)

This will print **I am here** to the web console of the browser you are using. Here is the screenshot of the output when run in the [JavaScript replit](https://replit.com/languages/nodejs)

![console.log string output](https://cdn.hashnode.com/res/hashnode/image/upload/v1646039599157/hWetqR4JE.png)

## 2. Variables
In addition to strings, you can log variables to inspect their values in the web console. Referring to our sum example, we can inspect the values of individual variables or all the variables. 

![console.log variable example](https://cdn.hashnode.com/res/hashnode/image/upload/v1646043019860/_8NuZu5c0.png)

It will print **10** for a and **20 30** for b and sum.

![console.log variable output](https://cdn.hashnode.com/res/hashnode/image/upload/v1646043666516/j4oGamnXD.jpg)

You can log strings and variables together in the web console.

![console.log variable & string example](https://cdn.hashnode.com/res/hashnode/image/upload/v1646044208911/jbjmj69ao.jpg)

## 3. Objects
While working with APIs, you may need to inspect the value of any object returned in a JSON response. You can log it to the web console. 

![console.log object example](https://cdn.hashnode.com/res/hashnode/image/upload/v1646045214323/3O7nrc33Z.jpg)

## 4. HTML elements
You can log any html element in the web console to inspect its values.


![console.log html element example](https://cdn.hashnode.com/res/hashnode/image/upload/v1646046038389/hPABwsdbf.png)

The output in the web console would be

![console.log html element output](https://cdn.hashnode.com/res/hashnode/image/upload/v1646046085174/062MPboAg.jpg)

These are most often uses of console.log() in **JavaScript**. If you have used it in different use cases, then do share with us in the comments. Happy Coding!


