The Browser Console and What It Can Do


For web developers, the browser console is one of the most important tool that helps the development process continue with ease. Generally speaking console.log()overcomes its responsibilities but we can take that further and use other methods of the console object itself.

Timers

console.time() used to track how long an operation takes. It starts a timer with the name you provided and when you call console.timeEnd() with the same name, the browser will output the milliseconds elapsed since the timer was started. You can have up to 10,000 timers running on a given page.

Groups

console.group() method creates a group in the console log, and can be called more than one in order to have inner groups until console.groupEnd() is called.

Styling the Output

Using %c directive with the logging gives you ability to add styling to your logs

console.log(“Boring message: %cred %corange”, “color: yellow; background-color:black”, “color: orange; background-color: red”, “boring message continues”);

Tables

The console.table() method displays the data as a table.

this.name = name;

Asserting

console.assert() method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

Counting

console.count() logs the number of times that this particular call to count() has been called. If a name is not provided the name becomes default

Tracing

The console.trace() method outputs a stack trace to the console.

Viewing Properties

The method console.dir() displays the list of the properties of the provided JavaScript object as an argument. The output is presented as a hierarchical collapsable listing that let you see the contents of child objects.

Profiling

The console.profile() starts recording a performance profile based on the browser profiling tools.

If you provide an argument to name the profile, this enables you to stop only that profile if multiple profiles are being recorded.

To stop recording call console.profileEnd().

Clearing

Last but not least, console.clear() clears everyting that has been logged.


Follow me on Instagram, Facebook or Twitter if you like to keep posted about tutorials, tips and experiences from my side.

You can support me from Patreon, Github Sponsors, Ko-fi or Buy me a coffee


Leave a Reply

Your email address will not be published.