‘Debugging’ is the process without which, development of applications would only be possible by the perfect programmers, and we all know there are no such programmers who don’t make a mistake or simply are ‘PERFECT’.
In the early stages of JavaScript, we used to call alert() to debug and get a variable’s value, whereas now we have the CONSOLE OBJECT.
“The console object provides access to the browser’s debugging console” – MDN Web Docs.
When talking about the Console API, usually developers use only some functions like console.log(), console.warn(),or console.error()to debug their application, but these aren’t the only weapons in the arsenal of CONSOLE. Often there are many other methods that can perfectly implement our requirements and improve debugging efficiency.
Earlier, I personally used only console.log() and no other methods, but one day I was introduced with different methods of the console, and the first thought that came into my mind was “where were you, all this time?!?” … This Blog Post is made to introduce other developers, with the most interesting console methods which I personally use in my daily life as a ‘JavaScript Developer’ to debug the code.
In this blog, we’ll get to know about several methods that the console object provides-
Let’s understand with an example:
In the above example, we simply passed data and voila! Now let’s use the second argument column on the same data to see its use-
If you see the above example, we are passing the name as the column. So, the table print only with the name property.
It’s a very important method to find out how many times a code block is executing.
Since JavaScript is not a very structured language, it can sometimes be hard to get an overview of what happened and when. This is when console.trace (or just trace in the console) comes handy to be able to debug JavaScript.
Also you can read - Promises in JavaScript(An Introductory Guide).
You can see my project developed in this article for a more interactive explanation. Lastly, I want to say that incorporating these methods in your day to day coding practice, will definitely make your work efficient and debugging slight hassle-free and less painful.