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

How to use the JS console.log function

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

Share

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

This article mainly explains "how to use the JS console.log function", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use the JS console.log function" bar!

1. Console.assert ()

This instruction is very useful when you only want to output the selected log, it will only output the error parameters, and if the first parameter is correct, it will not work.

Assertion (assertion)

2. Console.group () & console.groupEnd ()

You can use the console to group messages.

Group messages

3. Console.trace ()

This method tracks and displays when the code stops running.

Tracking

4. Console.count ()

This function records the number of calls to the count () function and has an optional argument, label.

If label is provided when called, the function records the number of times count () is called with that particular label.

If label is omitted during the call, the function records the number of times count () is called on this line.

Count

5. Console.table ()

Would you like to see JSON text that is suitable for easy to read?

Better visualization of the array!

6. Add styles to console messages

Do all console messages look the same? It's different now, making the important parts of the debug log look more eye-catching.

A message with color

You can change the color of specific words in the log in the following ways:

Highlight specific words

7. Console.time ()

Console.time () is used to trace the time consuming of the operation, and it is a good way to track the short time taken by JavaScript execution.

8. HTML in the console

Get the HTML element from the console in the same way that you check the element.

HTNL element display

9. Console.dir ()

Outputs the JSON form of the specified object.

10. Console.memory ()

Want to know how much browser memory is consumed by Javascript applications?

Memory

11. Use placeholders

The different placeholders are as follows:

% o: accept an object

% s: accept a string

% d: accept a decimal or integer

Placeholder introduction

12. Console.log () | info () | debug () | warn () | error ()

These statements identify the original string in different colors depending on the type of event.

13. Console.clear ()

Last but not least, use the clear () command to clear all console messages.

The following is something to add.

/ / time and time end console.time ("This"); let total = 0; for (let j = 0; j

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