Console Command Console detailed

Source: Internet
Author: User

Console Command Console detailed

What is a Console

The Console is a separate window for displaying JS and DOM object information. and inject 1 Console objects into JS, using this object
You can output information to the Console window.

Second what browser support Console

Many people may know that the Console is supported in Chrome and FireFox (FireBug). Other browsers are supported by
Not good. For example, IE8 's own development tools, although support Console, but the function is more monotonous, display objects are displayed
[Object,object], and you cannot click to view the properties inside the object. IE6, IE7 Although can install Developer Toolbar, but also
Console is not supported. The Console is supported by Safari and Opera, but it is not easy to use with Firebug and Chrome.
Now Firebug has launched the Firebuglite tool, which allows all browsers to support the console function, and use the UP and Firebug
Almost the same. See Http://
All subsequent demos, except for special instructions, are tested using Firebuglite under IE8.

Why don't you just use alert or write your own log

is not the same as using alert to display information, debugging programs? The alert popup will break the program,
If you want to display information in the loop, hand-clicking the Close window is exhausting. And the alert display object is always displayed as [object].
I write the log although you can display some object information, but a lot of feature support is not console good, after watching the console
The introduction to know.

Four Console.log (object[, Object, ...])

Console.log is the simplest way to output information to the console window, supporting multiple parameters, which will
These parameters are combined to display, e.g:

The first parameter of the Log method supports similar C-language printf string substitution patterns, such as the above example:

Log supports the following alternate modes:
%s instead of string
%d instead of integers
%f instead of floating-point values
%o Instead of Object

Five Console.debug,info,warn,error

These 4 methods are identical to the log method, except that the icons displayed are not the same as the text color, e.g

Six console. ASSERT (expression[, object, ...])

The Assert method is similar to assertions in unit tests, and when expression is false, output the following information, e.g:

Note: The Assert method is not supported in Firebuglite, Chrome and FireBug support

Seven Console.clear ()

This method clears all the information in the console

Eight Console.dir (object)

Prints all the properties of the object in a list, e.g:

Nine Console.dirxml (node)

Print out HTML code for HTML elements, e.g:

Ten Console.trace ()

The trace method can view the call stack information for the current function, that is, how the current function is called, e.g:

11 (object[, Object, ...]), groupcollapsed, GroupEnd

These 3 functions are used to group information such as log output, so that it is easy to read and view. Groupcollapsed
Method is the same as the group method, except that the displayed groupings are collapsed by default, e.g:

12 Console.time (name)/console.timeend (name)

We often need to test the execution time of the JS function, we may write our own code in the 1th statement and
The last 1 statements are subtracted from the current time. This set of functions actually implements this function, and time (name) creates 1 new
The timer. Timeend (name) stops the timer for the given name and displays the time. e.g:

13 Console.profile (name)/console.profileend ()

This set of methods is used to open the browser parser, which is used to analyze the JS execution between this set of functions,

Note: Firebuglite does not support profile function, is FireBug, Chrome supports profiles, but the content of the analysis is not
, interested students can study under their own.

14 Console.count ([title])

The Count method is used to count how many times the current code has not been executed and the title parameter can be output before the number of times
Additional titles to help with reading, e.g:
Note: Firebuglite does not support the Count method, which is printed 1000 times in Chrome and shows no FireBug as friendly.

XV console.exception (Error-object)

The exception method is used to print the exception object, unlike log printing, except ion also prints
The stack information for the exception call, e.g:
Note: The exception method is unique to FireBug, and Chrome and Firebuglite are not supported.

16 Console.table (data)

The table method displays the data object as a table, in the same way that the array or format is displayed.
JSON objects are very useful. E

Note: Table only supports FireBug, and is only available after the firebug1.6+ version.

Console is to help us learn and debug JS 1 very good tools, if you have not used before, and now start using it. You
Will find it can help you save a lot of development time.

Console Command Console detailed

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: 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.