a blog for those who code

Monday 11 May 2020

Better Logging than Console.Log

In this post, we will be looking at better logging than console.log but they are all similar. We all have written console.log, in some part of our career to find out the data or the bug, console.log seems to be a very powerful tool. But the problem is the logs can get confusing and messy if not handled well. Here in this post, we will be looking at more properties of console other than log.

Console.table() - This method displays the arrays and objects in a neat table. It takes two parameters as shown below

1. Data (object or array) - Required. The data to fill the table with
2. Columns (array) - Optional. The names of the columns to be displayed.

Whatever is displayed when using console.table is much more organized and easy to understand.

Console.count() - This method keeps a count of how many times any particular call to count() has been called. This is great because then you will actually see how many times a particular function has been called. It takes one optional parameter, a label that will just assign a label with the number of times a particular method has been called.


Console.asset() - This method is to check if the condition is passed or not, it will only write to the console if the assertion fails. The first parameter is what it will make the check on whereas the second one is the error message you want to display.


No comments:

Post a Comment