Some Javascript console commands are useful

Tram Ho

console.log() is the legendary command for debugging Javascript . But there are many other commands that can help you debug better or a little mind also helps you have a new experience when debugging javascript

The most basic case of show log in javascript is to display a string

Next comes the display of an object

When displayed in the console will look like the following

You can see, although two objects have been displayed, but there are no variable names displayed together. To know the variable name, you need to click on it. This can be solved using the following log

Then we will see the variable name corresponding to its data and reduce the number of console.log () lines.

console.table ()

In the above example, we have a better way to display variables in a more readable way. When you need to log variables with the same attributes or an array of objects, using console.table() will be great

The mouse trap in the Javascript Date.setMonth () function
Memory management in Javascript ()

Used when you want to group or nest related logs for easier reading.

It can also be used to clearly see the scope of each log() statement log()

For example, you log a user information

You can also use console.groupCollapsed() instead of if you want to collapse the groups. When you want to display it fully, just click the description button on the left to expand

console.warn () & console.error ()

Depending on the situation, you can display more readable logs using console.warn() or console.error()

Also we can customize, to be able to distinguish more than the types you want to log

You can change font-size , font-style and many other CSS

console.time ()

One important thing in programming is that the code needs to run fast. console.time() helps you know the runtime of the code

Hopefully the article will help you with different ways to use the best console.


Translated from author Yash Agrawal’s article

Optimize WHERE statements in MySQL
A few small tricks when using the Linux command line
Share the news now

Source : viblo