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.
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.
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
%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”);
console.table() method displays the data as a table.
this.name = name;
console.assert() method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.
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
console.trace() method outputs a stack trace to the console.
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
Last but not least,
console.clear() clears everyting that has been logged.