Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the skills of using console for JS debugging

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the skills of using console for JS debugging". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the skills of using console for JS debugging".

Tip # 1 console.trace ()

If you want to get the prompt location of the log information, you can get a stack trace with recorded data by using console.trace ().

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

If you are trying to find a more hidden performance problem, use console.time () to start calculating the time, and then use console.timeEnd () to print.

Tip # 3 console.memory

If your performance problems are more intractable and you are looking for a hidden memory leak, you may want to try and use console.memory (properties, not functions) to check your heap size status.

Tip # 4 console.profile ('profileName') & console.profileEnd (' profileName')

This is not a standard approach, but it is widely supported. You can use console.profile ('profileName'), and then use console.profileEnd (' profileName') to launch and end the browser performance tool-"performance profile" from the code. This will help you analyze exactly what you want and prevent you from clicking the mouse, which depends on the execution time of the program.

Tip # 5 console.count ("STUFF I COUNT")

In cases where functions or code are repeated, you can use console.count ('?') To calculate the number of times your code has been read.

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

Yes, conditional logging does not wrap your log in if-else:)

You can use console.assert (condition, msg) to record something when condition is false.

Disclaimer: in Node.js, this throws an Assertion Error!

Tip # 7 console.group ('group') & console.groupEnd (' group')

After writing so many journals, you may want to organize them. A small but useful tool is console.group () and console.groupEnd (). Using console groups, the console logs are organized together, and each group creates another level in the hierarchy. Call groupEnd () to decrease one level (go back to the previous level).

Tip # 8 String substitutions

When logging, you can replace merge variables with strings. These references are (% s = string,%i = integer,%o = object,%f = float).

Tip # 9 console.clear ()

So, after writing so many logs, it's time to clean up your console.

Tip # 10 console.table ()

In my opinion, this is a real "treasure"! You can use console.table () to print a very beautiful form!

Thank you for your reading, the above is the content of "what are the skills of using console for JS debugging". After the study of this article, I believe you have a deeper understanding of the skills of using console for JS debugging, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report