Nine console command Debug JS

Source: Internet
Author: User

The following nine console commands can help us to debug more easily

    • Commonly used console commands, the most common thing Console.log ()
1     // Common console commands, of which the most commonly used Console.log ()2     console.log ();  3 Console.info (' Some information ');  4 console.error (' error ');  5 Console.warn (' warn '        

    • Console.dir () Viewing the properties and methods of an object
1     // View information about the object 2     var objinfo={3 name: ' lazy ',4 age:20,5 sex: ' Male '  }; 7 console.dir (objinfo);           

    • Console.trace () traces the call path of a function, needs to know how a function is called, and adds console.trance () to it.
1//Tracing the call path of a function2functionAdd (a, b) {3Console.trace (); 4 return a+b; 5 } 6 var x=add2 (1,1< Span style= "color: #000000;" >);  7 function add1 (a, B) { Span style= "color: #008080;" > 8 return add (a, b)  9 Span style= "color: #000000;" >}10 function add2 (a, b {11 return add1 (a, b); 12}             

    • Console.time () console.timeend () shows a part of the program run time
1     // chronograph function 2     console.time (' console Timer ");  for (var i=0;i<100;i++) { }6 console.timeend (' Console timer ");       

    • Console.profile (name) Console.profileend (name) The run time of each part of the parser
1//Performance analysis, analysis of the running time of various parts of the program, identify bottlenecks2functionAll () {3Forvar i=0;i<10;i++){4 FUNC01 (10);5}6 FUNC02 (100);7}8functionFUNC01 (count) {9Forvar i=0;i<count;i++){Ten  -one}   -function func02 (count) {+ for (var i=0;i<count;i++) {  console.profile} (' Performance Analyzer ');  All ();  Console.profileend (' Performance Analyzer ');               

    • Console.group () console.groupend () is displayed in group form
1     // Information Group 2     console.group (' First Group ');  3 Console.log (' First article ');  4 Console.log (' Second article '); console.groupend ();  6 Console.group (' Second group ');  7 Console.log (' First article ');  8 Console.log (' Second article ');  9 console.groupend ();               

    • Console.dirxml () Displays the contents of a node
1     // Display the contents of a node 2     var mynode=document.getelementbyid (' sp-float ');  3 console.dirxml (mynode);     

    • Support placeholders
1     // placeholder that supports printf placeholder Format,%s,%d,%i,%f,%o2     console.log ('%d%d months ', 2016,8,10);  

    • Console.assert () to determine if a variable is true
1     // Determine if a variable is true (if the result is false, output the appropriate information in the console and throw an Error)2     console.assert (true==0);   

Nine console command Debug JS

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.