js console output console

 

introduce:

   You can see the console of js in firefox's firebug or ie and google's f12 debug mode. The debug mode control of these mainstream browsers can output some information. Some of your js code tests can be input directly in the console window and run to view As a result, the time for deploying the project and refreshing the page is saved; of course, you have some special code tests, such as those that require background data or page effects. In general, everyone likes to use js code to directly use alert to output test information. The interrupt program jumps out of the thread; at this time, there is also a good choice to use the log of the console, that is, console.log; the following will introduce some usages of the console one by one, some of which are taken from the Internet:

1.console.log

console.log(object[, object, ...])
prints a message to the console. If there are multiple parameters, they will be separated by spaces when outputting.

The first argument can be a string containing formatted placeholder output, for example:

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

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

console.log("The", animal, "jumped over", count, "tall buildings");

Also, these two methods can be used in combination. If formatting placeholders are used and more arguments are provided than there are placeholders, the extra arguments are appended to the string in a space-separated manner, like:

console.log("I am %s and I have:", myName, thing1, thing2, thing3);

If the parameter is a Javascript object, then the output in the console is not static text, but an interactive hyperlink. Click the hyperlink to view the HTML, CSS, Script, and DOM windows of the object. The format string % can be used. o in place of Javascript objects.

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

 

Format string list:

format string

Types of

%s

string

%d, %i

Integer type (numeric type is not supported yet)

%f

Floating point (numeric type is not supported yet) 

%O

link object

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

console.debug(object[, object, ...])
prints a message to the console containing a hyperlink to where the code was called. If the command is entered directly on the console, the hyperlink will not appear (same as console.log()).

console.info(object[, object, ...])
prints to the console a message with an "info" icon and a hyperlink to where the code was called.

console.warn(object[, object, ...])
prints to the console a message with a "warning" icon and a hyperlink to where the code was called.

console.error(object[, object, ...])
prints to the console a message with an "error" icon and a hyperlink to where the code was called.

console.assert(expression[, object, ...])
tests whether the expression expression is true. If not true, will write a message to the console and throw an exception

console.dir(object)
prints all the properties of an object in a list, similar to how you would view a DOM window.

console.dirxml(node)
输出一个HTML或者XML元素的XML源代码。和你在HTML窗口看到的相似。

console.trace()
Prints an 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 that were passed as arguments to eachfunction. You can click each function to take you to its source in the Scripttab, and click each argument value to inspect it in the DOM or HTML tabs.

console.group(object[, object, ...])
输出一条消息,并打开一个嵌套块,块中的内容都会缩进。调用console.groupEnd()关闭块。该命令可以嵌套使用。

console.groupEnd()
关闭最近一个由console.group打开的块。

console.time(name)
创建一个名字为name的计时器,调用console.timeEnd(name)停止计时器并输出所耗时间(毫秒)。

console.timeEnd(nam)

 

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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326460497&siteId=291194637