Console commands are embedded in JavaScript through the console commands in the Browser development tool, outputting specific information or logs for debugging purposes.
Our common chrome and Firefox can be F12 to open development tools.
A few common console commands are briefly described below:
(1) General information output
Console.log () is our most commonly used command, just to pass in the content we want to output:
Console.log ("This is the message I want to output");
In addition to the Console.log () command, there are three other kinds of commands:
Console.info ("This is the message I want to output");
Console.error ("error message");
Console.warn ("warning message");
They can be seen from the names of these four commands, which are used to show different types of information and make our information output more normative (personal).
(2) General Information packet output
A lot of information output, we can use the packet output to group them, convenient for us to view:
Console.group ("First group start"), Console.log ("first Group first"), Console.log ("first Group II");console.groupend (); Console.group ("Start of the second group");Console.log ("The first of the second group"); Console.log ("second group, second article"); console.groupend ();
The Console.group () command is used to start the grouping, and Console.groupend () is used to end the grouping.
(3) Object output
Console.dir () is a specialized output of all methods and properties of an object, so we can view the object's information without having to traverse it ourselves:
var obj = { "haha", "Doubi"};console.dir (obj);
(4) Dom output
The Console.dirxml () command is dedicated to outputting the Html/xml code that a node contains:
var div = document.getElementById ("demo"); Console.dirxml (div);
Because of too much content, the picture is not truncated.
(5) Function call trajectory monitoring
var x = test3 (1); function Test (a) { console.trace (); return A;} function Test1 (a) { return Test (a);} function Test2 (a) { return test1 (a);} function Test3 (a) { return test2 (a);}
(6) Chronograph function
Sometimes we need to monitor the time spent on a piece of code, which we can usually do:
var New Date (); for (var i = 0; i <; i++) {} var New -time1);
We can also help us do this through Console.time () and Console.timeend ():
Console.time ("timer"); for (var i = 0; i < i++) {}console.timeend ("timer");
It is important to note that the parameters in both commands are consistent before the timing information is output.
OK, in the next familiar with the console command of these, if there are missing console related to other common commands, also welcome to add OH.
Browser console command Debug--console