javascript console hidden pieces

The Javascript Console Hidden Pieces, console.debug, console.table, console.error

Javascript provides the console object which is a useful utility that can be used to simulate browser console perhaps the most used function used in common is console.log() but there are other useful methods in console that can be used.

 

 

Console.log()

This is the most commonly used function in the Console object and it’s used to log any textual message to the browser console.

 

Console.table(data)

The console.table() logs arrays or objects to the console but it differs from console.log() is that it displays it as a table in much the same way as html table. The first column has a header of “index” and this is the item indices for arrays or property names for objects.

javascript console table()

For array of arrays:

In case of objects:

javascript console table

Using array of objects:

 

Console.debug(obj1, obj2,…)

The console.debug() acts like the same as console.log() but console.debug() only appears in browser if debug level is enabled which you may be turned off by default.

javascript console debug

As you see the logs are displayed in consecutive order corresponding to the function argument order. 

Using substitution strings

 

Console.error()

Logs an error message to the console when the error display level is enabled. In this level the error is styled with a red color by default indication that this is an error.

Console.warn()

Logs an error message to the console when the warning display level is enabled. In this level the error is styled with an yellow color by default indication that this is an error.

 

Console.info()

This function actually used to display informative messages usually a small “i” icon is shown next to the message in web browsers. This level is shown when the info display level is enabled.

 

Console.time()

Starts a timer in the console to track how long an operation could take, you may have up to 10000 timers running on a single page. The time() function takes a label to mark that timer, then to stop the timer use timeEnd() passing in the timer label as the argument and use timeLog() to the log the timer messages.

The time is logged when calling timeLog() and timeEnd().

 

Console.trace()

This function displays a stack trace starting from the point the code begins executing:

 

 

Console.group() and console.groupEnd()

Those functions used to group log messages into hierarchical display when printed into the console. Whenever you started console.group() the log messages indents by some space, the inner groups also takes indentation relative to the outer most group, to close the group use groupEnd().

 

javascript console group

Console.clear()

This function just clears the console from log messages:

 

Share this: