JavaScript — Console API

Vaibhav Tandon
Jun 9 · 3 min read

Console API is one of the most important tools used while debugging. It helps the developers or more appropriately prevent the developers from applying the alert() again and again.

Console API can be used for:-

  • Logging
  • Asserting
  • Clearing
  • Counting
  • Timing
  • Grouping

So let's start with the first one,


console.log() is the most common method that is used to log the values to the console.

Instead of log() there are some other logging methods such as info(), warn() and error .

Outputs will somewhat look like this,

Now, the stack trace can be triggered by using trace()

There are also console.dir() , console.dirxml() and console.debug()


It is basically used for printing the object in a formatted way

console.dirxml() is used to print the DOM elements.

console.debug() is just an alias for console.log().


console.assert() is used to perform assertion tests.


If you want to clear the console then this console.clear() is used.


The console.count() is used to count the number of times a particular statement has been invoked.



The console object has time() and timeEnd() methods that help with analyzing the performance of pieces of your code. You first call console.time() by providing a string argument, then the code that you want to test, then call console.timeEnd() with the same string argument.


String passed inside of the time() and timeEnd() should always be same.

GROUPING and console.groupEnd() are used to group the console messages as


These are some of the methods of the Javascript Console API.

If you like this post, just support me by pressing 👏.

Thank you

Vaibhav Tandon

Written by

Android | Front End Web dev

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade