10 Tip Debug Javascript is like a Pro with console

Tram Ho

Hopefully I can give you some tips I didn’t know before and this will make you a pro in the debugger .

Tip1 console.trace ()

If you want to know where the logs are located, then use console.trace() which will retrieve the log data to be written to the stack.

Tip # 2 console.time () && console.timeEnd ()

If you want to find a problem that you are running that you do not know how to reduce performance, you can use console.time() or console.timeEnd() .

Tip # 3 console.memory

If your performance problem is even more complicated and you are leaking to see which memory is being used but not what you want you can use: console.memory (properties, not functions) to test HEAP device status.

Tip # 4 console.profile (‘profileName’) & console.profileEnd (‘profileName’)

This is not a standard that is widely used. You can start and end a browser performance tool – performance information from code using console.profile('profileName') and console.profileEnd('profileName') . This helps you set up exactly what you want and prevents you by time-consuming mouse clicks

Tip # 5 console.count (“STUFF I COUNT”)

In case you want to read or write the number of function calls you can use

Tip # 6 console.assert (false, “Log me!”)

You can use console.assert(điều , msg) to log something when the check is made.

Tip # 7 console.group (‘group’) & console.groupEnd (‘group’)

After you have written a lot of logs and you want to reorganize them. A small but useful tool console.group() & console.groupEnd() uses console.group() , console.log() to group all of them. While each group creates a hierarchy. When using groupEnd() to reduce one.

Tip # 8 String substitutions

When logging you can use variables to replace strings. For example (% s = string,% i = integer,% o = object,% f = float).

Tip # 9 console.clear ()

Well, I have written too many logs from time to time

Tip # 10 console.table ()

I have left this tip until the end of my introduction. You can actually print beautiful tables with users logged in with console.table()

Finally, hopefully with tips like this will make debugging more efficient and interesting, right?

Reference link: https://medium.com/appsflyer/10-tips-for-javascript-debugging-like-a-pro-with-console-7140027eb5f6

Share the news now

Source : Viblo