JS Debug Tool Console command

Source: Internet
Author: User

Source:

Http://www.jb51.net/article/56504.htm

I. Commands to display information

The code is as follows:


<!DOCTYPE HTML><HTML><Head><title>Common Console Commands</title><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /></Head><Body><Scripttype= "Text/javascript">Console.log ('Hello'); Console.info ('Information'); Console.error ('Error'); Console.warn ('Warning');</Script></Body></HTML>

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)

The 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
The code is as follows:


<!DOCTYPE HTML><HTML><Head><title>Common Console Commands</title><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /></Head><Body><Scripttype= "Text/javascript">Console.group ("first set of information"); Console.log ("First set of first: my XX (http://www.jb51.net)"); Console.log ("The First group second article: XXX (http://jb51.net)");      Console.groupend (); Console.group ("Second set of information"); Console.log ("The second group first article: Program Enthusiasts QQ Group: 80535344"); Console.log ("Second group, article two: Welcome to join"); Console.groupend ();</Script></Body></HTML>

Effect:

 

Iv. Viewing the information of an object

Console.dir () can display all properties and methods of an object.
The 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 in a node of a Web page.

The code is as follows:
<!DOCTYPE HTML><HTML><Head><title>Common Console Commands</title><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /></Head><Body><DivID= "Info"><H3>My blog: www.ido321.com</H3><P>Program enthusiasts: 259280570, you are welcome to join</P></Div><Scripttype= "Text/javascript">varInfo=document.getElementById ('Info'); Console.dirxml (info);</Script></Body></HTML>

Effect:

 

Vi. Judging 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.

The code is as follows:
<script type= "Text/javascript" > var result = 1;  Console.assert (result);  var 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.

The code is as follows:
 <script type= "Text/javascript" >/*    How the function is called, in which the Console.trace () method is added to  */ function      add (A, b) {console.trace ();   return  a+B;   var  x = add3 (1,1 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, chronograph function

Console.time () and Console.timeend () are used to display the elapsed time of the code.

The 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


Performance analysis of Console.profile ()

Performance analysis (Profiler) is the analysis of the various parts of the running time, to find out the bottleneck, the method used is Console.profile ().

The code is as follows:
<script type= "Text/javascript" >functionAll () {alert (11);  for(vari=0;i<10;i++) {Funca (1000);} FUNCB (10000); }functionFunca (count) { for(vari=0;i<count;i++) {}}functionFUNCB (count) { for(vari=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.