JS Console Output Console

Source: Internet
Author: User
Tags stack trace

Introduced:

JS Console you can be in Firefox firedbug or IE and Google F12 debug mode to see, these mainstream browser debugging mode control can output some information, Some of your JS code tests can be entered directly in the console window and then run to view the results, save the deployment project and refresh the page time; Of course, you have some special code testing, such as the need for background data or page effects, In general, we like to use the JS code directly using the alert output test information, which will interrupt the program to jump out of the thread; that's a good choice. That is, using the console's log, that is console.log; Here are some of the uses of the console, section from the network:

1.console.log

Console.log (object[, Object, ...])
Output a message on the console. If there are multiple parameters, the output is separated by a space.

The first argument can be a string that contains the formatted placeholder output, for example:

Console.log ("The%s jumped over%d tall buildings", animal, count);

The example above can be replaced with the following code with unformatted placeholder output:

Console.log ("The", Animal, "jumped over", count, "tall buildings");

Also, these two methods can be used in combination. If you use a format placeholder and you supply more arguments than the number of placeholders, the extra arguments are appended to the string in a space-delimited manner, like this:

Console.log ("I am%s and I have:", MyName, Thing1, Thing2, thing3);

If the parameter is a JavaScript object, then the console output is not static text, but an interactive hyperlink, click the hyperlink to view the object's HTML, CSS, Script, Dom window, can be formatted string%o instead of JavaScript object.

Console.log ("Body tag is%o", document.body);

To format a list of strings:

formatting strings

Type

%s

String

%d,%i

Integral type (digital type is not supported temporarily)

%f

Floating-point type (digital type is not supported temporarily)

%o

Linked objects

2. Other levels, debug, Warn, error, assert, etc.

Console.debug (object[, Object, ...])
Outputs a message in the console that contains a hyperlink to the location of the code call. If you enter the command directly in the console, no hyperlinks (as in Console.log ()) will appear.

Console.info (object[, Object, ...])
Output a message with the info icon and a hyperlink to the code call location on the console.

Console.warn (object[, Object, ...])
Output a message with a warning icon on the console and a hyperlink to the location of the code call.

Console.error (object[, Object, ...])
Output a message with an error icon on the console and a hyperlink to the code call location.

Console.assert (expression[, Object, ...])
Tests whether an expression is true. If it is not true, a message is written to the console and an exception is thrown

Console.dir (object)
Output all properties of an object as a list, a bit similar to what you see in the Dom window.

Console.dirxml (node)
Outputs an XML source code for an HTML or XML element. Similar to what you see in the HTML window.

Console.trace ()
Prints a interactive stack trace of JavaScript execution at the point where itis called.

The stack trace details the functions onthe stack, as well as the values of the were passed as arguments to Eachfunction. You can click All function to take the Scripttab, and click each argument value to inspect it in the DOM or HTML tabs.

Console.group (object[, Object, ...])
Outputs a message and opens a nested block in which the contents of the block are indented. Call Console.groupend () to close the block. The command can be used in a nested set.

Console.groupend ()
Close the most recent block opened by Console.group.

Console.time (name)
Create a timer named name, call Console.timeend (name) to stop the timer and output the elapsed time (in milliseconds).

Console.timeend (NAM)

Original address: http://blog.csdn.net/yangkai_hudong/article/details/16885513

JS Console output 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.