Introduction:
JS Console you can see in Firefox firedbug or IE and Google's F12 debugging mode, these mainstream browser debugging mode of control can output some information, Some of your JS code tests can be entered directly in the console window and then run the view results, save the deployment of the project and refresh the page time; Of course, you have some special code testing, such as the need for background data or page effects, Generally, everyone likes to use the JS code directly using alert output test information, this will interrupt the program to jump out of the thread; At this time there is a good choice that is the use of the console log, that is console.log; Here are some of the uses of console, Partially excerpted from Network:
1.console.log
Console.log (object[, Object, ...])
Output a message at the console. If you have more than one parameter, the output separates the parameters with 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 code with the following unformatted placeholder output:
Console.log ("The", Animal, "jumped over", count, "tall buildings");
And, these two methods can be used in combination. If you use a formatted placeholder that provides 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, available formatted string%o instead of JavaScript objects.
Console.log ("Body tag is%o", document.body);
Format a list of strings:
format string |
Type |
%s |
String |
%d,%i |
Integral type (no support for digital type) |
%f |
Floating-point type (no support for digital type) |
%o |
Linked objects |
2. Other levels, debug, Warn, error, assert, etc.
Console.debug (object[, Object, ...])
Prints a message in the console containing a hyperlink to the location of the code call. If you enter the command directly on the console, the hyperlink (as Console.log ()) does not appear.
Console.info (object[, Object, ...])
Output a message with an "info" icon in the console and a hyperlink to the location where the code is called.
Console.warn (object[, Object, ...])
Output a message with a warning icon in the console and a hyperlink to the location where the code is called.
Console.error (object[, Object, ...])
Output a message with an "error" icon in the console and a hyperlink to the location where the code is called.
Console.assert (expression[, Object, ...])
Tests whether an expression expression is true. If not true, a message is written at the console and an exception is thrown
Console.dir (object)
Outputting all the properties of an object in a list is a bit like the way you look at the Dom window.
Console.dirxml (node)
Output an XML source code for an HTML or XML element. Similar to what you see in the HTML window.
Console.trace ()
Prints an interactive stack trace of JavaScript execution in the point where itis called.
The stack trace details the functions onthe stack, as as as the "the" and "the" were passed as arguments to Eachfunction. You can click each 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 the Console.groupend () close block. This command can be nested in use.
Console.groupend ()
Closes the most recent block opened by Console.group.
Console.time (name)
Creates a timer named name, calling Console.timeend (name) to stop the timer and output the elapsed time (in milliseconds).
Console.timeend (NAM)