JS Debug Tool Console command

Source: Internet
Author: User

This article mainly introduces the JS Debugging Tool console command in detail, the need for friends can refer to the next

I. Commands to display information

Copy CodeThe code is as follows:<! DOCTYPE html> < html> < head> < title> common console commands </title> < meta http-equiv= "Content-type" Content= "text/html; Charset=utf-8 "/>

The most common is the console.log.

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

Copy CodeThe code is as follows:< script type= "Text/javascript" > Console.log ("%d years%d months%d days", 2011,3,26); </script>

Effect:

Iii. Grouping of information

Copy CodeThe code is as follows:<! DOCTYPE html> < html> < head> < title> common console commands </title> < meta http-equiv= "Content-type" Content= "text/html; Charset=utf-8 "/>

Console.log ("First Group first: my XX (http://www.jb51.net)");

Console.log ("First Group II: XXX (http://jb51.net)");

Console.groupend ();

Console.group ("Second set of Information");

Console.log ("The second group first: program Enthusiasts QQ Group: 80535344");

Console.log ("Second group II: welcome you to join");

Console.groupend (); </script> </body>

Effect:

Iv. viewing an object's information Console.dir () can display all properties and methods of an object.

Copy CodeThe code is as follows:< script type= "Text/javascript" > var info = {blog: "Http://www.jb51.net", qqgroup:80535344, Message: " Program enthusiasts welcome you to join "}; Console.dir (info); </script>

Effect:

V. Display the contents of a node Console.dirxml () is used to display the Html/xml code contained by a node of a Web page (node).

Copy CodeThe code is as follows:<! DOCTYPE html> < html> < head> < title> common console commands </title> < meta http-equiv= "Content-type" Content= "text/html; Charset=utf-8 "/>

Effect:

Determine if 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 in the console and an exception is thrown.

Copy CodeThe code is as follows:< script type= "Text/javascript" > var result = 1;   Console.assert (result);   var year = 2014; Console.assert (Year = = 2018); </script>

1 is a value of 0, is true, and the second is false, displaying an error message on the console

Tracing the call trajectory of the function. Console.trace () is used to track the call path of a function.

Copy CodeThe code follows how the:< script type= "Text/javascript" >/* function is called, in which the Console.trace () method is added to the */function add (A, b) {     Console.trace ();   return a+b;   } var x = ADD3 (n);   function Add3 (A, b) {return add2 (A, b);}   function Add2 (A, b) {return add1 (A, b);} function Add1 (A, B) {return Add (A, b);} </script>

Console output Information:

Eight, the Chronograph function Console.time () and Console.timeend (), used to display the code run time.

Copy CodeThe code is as follows:< script type= "Text/javascript" > Console.time ("console timer one"); for (Var i=0;i<1000;i++) {for (Var j=0;j<1000;j++) {}} console.timeend ("Console timer one"); </script>

Run Time is 38.84ms

The performance analysis (Profiler) of Console.profile () is to analyze the running time of each part of the program, to find out the bottleneck, and to use the method of Console.profile ().

Copy CodeThe code is as follows:< script type= "Text/javascript" > Function all () {alert (11);         for (Var i=0;i<10;i++) {Funca (1000);}       FUNCB (10000); }

function Funca (count) {for (Var i=0;i<count;i++) {}}

function FUNCB (count) {for (Var i=0;i<count;i++) {}}

Console.profile (' Performance Analyzer ');   All (); Console.profileend (); </script>

Description, LZ test, in all () without alert, control bar no output, plus, there is a performance analysis table, temporarily unclear why, if you know, you can comment.

JS Debug Tool Console command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.