I. Commands to display information
Console.log ("normal"); // used to output general information Console. Info ("Information"); // used to output the console of informational information. Error ("error"); // used to output error message console. warn ("Warn"); // for output warning messages
Second, Dot: character (%s), Integer (%d or%i), floating-point number (%f), and Object (%o);
Console.log ("%s", "string"); // character (%s)Console.log ("%d%d months%d days", 2016,8,29); // Integer (%d or%i)console.log ("Pi is%f", 3.1415926); // floating point (%f) var dog == "Da Mao" = "Yellow" = "female Dog"; Console.log ("%o", dog); // object (%o)
Third, Information Group (Console.group (), Console.groupend ())
Console.group ("First set of Information"); Console.log ("First Group first: my Blog"); Console.log ("First Group II: CSDN"); Console.groupend (); Console.group ("Second set of Information"); Console.log ("The second group first: program enthusiasts QQ Group"); Console.log ("second group II: welcome you to join"); Console.groupend ();
Iv. displaying objects in a tree-like structure (Console.dir () can display all properties and methods of an object)
var info = { "Alan" , "I", "nothing" ,function () { returnthis. Name; }} Console.dir (info);
V. Display the contents of a node (Console.dirxml () to display the Html/xml code contained in a node of a Web page)
var node = document.getElementById ("info"+ = "<p> added element display </p>"; Console.dirxml ( node);
Six, determine whether the variable is true (Console.assert () is used to determine whether an expression or variable is true, only the expression is false, output a corresponding rest, and throw an exception)
var false ' only output when Testobj is False! ‘);
Seven, chronograph function (Console.time () and Console.timeend (), used to display the code run time)
Console.time ("console Timer"); for (var i = 0; i < 10000; i++) { for (var j = 0; J < 10000; J + +) {} }conso Le.timeend ("console Timer");
Performance Analysis Performance profile (that is, the analysis of the various parts of the running time, to find out the bottleneck, using the method is Console.profile () and console.proileend ();)
functionAll () {//alert (one); for(vari = 0; I < 10; i++) {Funca (100); } FUNCB (1000);}functionFunca (count) { for(vari = 0; I < count; i++){};}functionFUNCB (count) { for(vari = 0; I < count; i++){};} Console.profile ("Performance Analyzer"); All (); Console.profileend ();
Detailed information is viewed in the "Profile" tab of the Chrome console
Ix. Console.count () Number of times the code was executed
function myFunction () { console.count ("number of MyFunction executed");} MyFunction (); // number of MyFunction executed: 1myFunction (); // number of MyFunction executed: 2myFunction (); // number of MyFunction executed: 3
X. Keys and values, to be entered in the browser
Xi. console.table Table Display method
var mytable = [ { "Alan", "man" , "+" }, { "Wu", "Gril", "i" }, { "Tao", "Man and Gril", "}]console.table" (mytable);
12. The Chrome console natively supports jquery-like selectors, meaning you can select the DOM section with $ plus a familiar CSS selector.
$ ("body"); // Select Body Node
13. Copy copies the contents obtained from the console to the Clipboard by this command
copy (document.body); Copy bodycopy (document.getElementById ("info")); Copy the node of an ID element
14. The $_ command returns the results of the most recent expression execution, $0-$4 represents the last 5 DOM nodes you have selected
XV, using the console output text, pictures, with the beginning of%c, the following text on the printed information, the next parameter is the style attributes;
Console.log ("Please specify in the email%c from: Console", "Font-size:16px;color:red;font-weight:bold;");
Console command to make JS debugging easier