Browser console command Debug--console

Source: Internet
Author: User

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

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.