In your development career, you mostly know about the console.log() but the console API can do many things that you may don’t know. HERE, in this article, we are going to learn all about console API with Good VS Bad practice.
Let’s start with consoling the console object.
Write console.log(console) in your browser’s console editor and you found the list of APIs provided by the console object. Each API purpose is unique and useful in certain cases.
Below are my explanations of the most useful APIs in console object.
console.assert() – If condition false then only give an error. It eliminating the need for if condition and keep your code clean.
We can start a timer with the console by calling time, then call timeLog to measure the elapsed time. It provides a simple solution for measuring performance.
The console.clear() method clears the console
Writes to the console the number of times that particular console.count() is called.
This method writes a message to the console.
The console.warn() method writes a warning to the console.
The console.error() method writes an error message to the console.
The console.trace() method displays a trace that shows how the code ended up at a certain point.
We can also apply the style in the console.log(). Use the special %c character to add some style.
Thank you for reading this article.