Some tips to help debugging with consoles are easier

Tram Ho

During the coding process we probably need a lot of console support for debugging. One of the most useful and popular commands that any programmer knows is console.log . But there are many other methods that support with a variety of features and a clear display interface for easier debugging that you may not know about. In this article I will share some effective methods with the console in the hope of helping a lot of you in the debugging process.

1 Console.log ()

This is the basic method for displaying a string or a value on the console screen. For example, we have two objects in turn

and we want to display their values ​​for comparison, instead of using 2 statements, we can use console.log(obj1, obj2) to easily compare each attribute easily and reduce command line minority.

2 Console.table ()

Another effective way to observe the values ​​in objects is easier by displaying them in table form.

Some Javascript console commands are useful
Chrome’s Console tricks

3 Console.trace ()

Javascipt is a tightly structured language, so it’s difficult to know what the timing of functions is, especially when we’re debugging someone else’s code. Don’t worry, let console.trace() do it. The following example will help us show the trace how the function executes.

4 Console.group ()

console.group() will be useful when we want to group logs related to each other to make it easier to observe.

5 Console.time ()

To know how long it takes to execute a block, especially loops, this is a very effective method. For example

6 Console.count ()

In case the function runs multiple times, you can count its running times with console.count() . For example

Here are some effective methods when we debugging with consoles hoping to make it easier to debugging.

Share the news now

Source : viblo