–Power Of Console.log–

Photo by Denise Jans on Unsplash

–Power Of Console.log–

·

2 min read

All of us want to debug our code faster with less urges to throw our computer and the console is the most powerful tool to understand our code functionality better and to debug our code, and console.log is just the tip of the iceberg of how you can format/exploit/style your dev console outputs. Let’s overview a list of useful commands to give you that something extra.

Console.dir()

Let’s create an object for this example

By simply using console.log you are preventing yourself from a better visualization of the student object.

Substitute this with console.dir() and truly enjoy a better view.

Console.table()

I understand; you want even more clarity with your long server response log. Using console.table() might be the solution for you

This method will print your objects and arrays in a clear fashion. Allowing hard-to-read data to be finally decrypted.

Console.assert()

I bet you can confidently say to have performed operations perfect for this function basically every day. Think about logging to discover if an object contains some data. Or logging to follow the flow of some conditions. With console.assert() you can log data if a condition is false like this:

Console.count()

Instead of creating counters, or squeezing your eyes to count how many times something was printed, just use console.count() . You can provide a label to this function which will log an incremented counter every time that label appears to be printed.

Console.time() — timeLog() — timeEnd()

A good one for your timings. Whenever you have to calculate an amount of time passing, use a combination of these three functions. Use console.time() to start a timer. Then console.timeLog() to print the elapsed time since the timer started. And finally, stop the timer when you’re done using console.timeEnd() .