Photo by Lee Campbell on Unsplash

Playing with Javascript Console

Md. Abu Talha
InfancyIT
Published in
4 min readNov 27, 2018

--

When we talk about the console, we imagine about printing some string or JSON data for the purpose of development. Most of the time we use console.log() for debugging. But there are some other useful methods provided by javascript console. Today we will discuss the methods and there use cases.

1# console.log() / console.info()

When we want to print a string or just want to print the JSON data then it is the first choice.

Outputs an informational message to the console.

2# console.warn()

When we want to check the warning of our function and where it creates then we should use this method.

Outputs a warning message to the console.

3# console.error()

In our function, most of the time we use try catch block for the handling exception. we can use this method in the catch block to check the error.

Outputs an error message to the console.

4# console.trace()

If we want to know where the log is being prompted, we can use console.trace() to get the stack trace with the logged data.

Outputs a stack trace to the console.

5# console.count()

Sometimes we need to run a function with interval/timeout or in a loop, in this situation we can count the number that the function hit by this counting method.

Logs the number of times that this particular call to count() has been called

6# console.time() — console.timeEnd()

We can get the time that a function takes to process its data by using these console time method. First, we need to use the time() method begin of the function and timeEnd() at the bottom of the function. We can pass the parameter in these two functions, but the parameter needs to be the same in two places.

time() starts a timer and timeEnd() stops a timer that was previously started

7# console.group() — console.groupEnd()

After writing so many logs, we might want to organize them. Using the console group, our console logs are grouped together, while each grouping generates another level in the hierarchy.

Creates a new inline group in the console. This indents following console messages by an additional level, until console.groupEnd() is called

console.groupCollapsed() — console.groupEnd()

This method is similar to console.group() method. Creates a new inline group in the console. However, the new group is created collapsed. The user will need to use the disclosure button to expand it.

8# console.table()

We can generate the table in the console by using table() method. We can generate the table by array data.

Displays tabular data as a table

We can also generate a table from an object.

9# console.clear()

Sometimes we fetch that the console is so messy we can clear the console by clear() method.

10# String substitutions

When logging, you can incorporate variables using string substitutions. These references should be types (%s = string, %i = integer, %o = object, %f = float).

11# Console Design:

If you want to design your console then you should check this Javascript Console Styling

--

--