Home  >  Article  >  Web Front-end  >  Detailed explanation of js debugging tool Console command_javascript skills

Detailed explanation of js debugging tool Console command_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:33:101350browse

1. Commands to display information

Copy code The code is as follows:




Common console commands






The most commonly used one is console.log.

2: Placeholder

The above concentration of console supports the placeholder format of printf. The supported placeholders are: characters (%s), integers (%d or %i), floating point numbers (%f) and objects (%o)

Copy code The code is as follows:



Effect:

3. Information Grouping

Copy code The code is as follows:




Common console commands






Effect:


4. View object information

console.dir() can display all properties and methods of an object.

Copy code The code is as follows:


Effect:

5. Display the content of a node

console.dirxml() is used to display the html/xml code contained in a node of the web page.

Copy code The code is as follows:

Effect:


6. Determine whether the variable is true

console.assert() is used to determine whether an expression or variable is true. If the result is no, a corresponding message is output to the console and an exception is thrown.

Copy code The code is as follows:


1 is a non-zero value, which is true; while the second judgment is false, an error message is displayed on the console

7. Track the calling trace of the function.

console.trace() is used to trace the calling trace of the function.

Copy code The code is as follows:


Console output information:


8. Timing function

console.time() and console.timeEnd() are used to display the running time of the code.

Copy code The code is as follows:


The running time is 38.84ms


9. Performance analysis of console.profile()

Performance analysis (Profiler) is to analyze the running time of each part of the program and find out where the bottleneck is. The method used is console.profile().

Copy code The code is as follows:


Explain that during the LZ test, alert was not added to All(), and the control bar had no output. After adding it, there was a performance analysis table. The reason is not yet clear. If you know, you can comment.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn