I. Commands to display information
Console.log (' details '); Console.error (' error '); Console.warn (' warning ');
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)
Console.log ("%d years%d months%d days", 2015,6,28);
Iii. Grouping of information
Console.group ("My Information"); Console.log ("User name: Tpythoner") console.log ("My Blog: Oschina (Console.groupend ();
Iv. Viewing the information of an object
Console.dir () can display all properties and methods of an object.
var info = {' username ': ' tpythoner ', ' email ': ' [email protected] '}; Console.dir (info);
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.
VI. 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.
var result = 1;console.assert (result); var = 2015;console.assert (Year = = 2016);
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.
<script type= how the "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>
eight, Timing function
console.time () and Console.timeend (), which displays the elapsed time of the code.
<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>
Performance analysis of Console.profile ()
function Dotask () {Dosubtaska (1000); Dosubtaska (100000); DOSUBTASKB (10000); DOSUBTASKC (1000,10000);} function Dosubtaska (count) {for (Var i=0;i<count;i++) {}} function Dosubtaskb (count) {for (Var i=0;i<count;i++) {}} function DOSUBTASKC (countx,county) {for (Var i=0;i<countx;i++) {for (Var j=0;j<county;j++) {}}}console.profile () ;d otask (); Console.profileend ();
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 ().
Nine console commands to make JS debugging easier