Home >Web Front-end >JS Tutorial >js console output method (detailed explanation)

js console output method (detailed explanation)

高洛峰
高洛峰Original
2016-12-05 10:52:452047browse

console.log(object[, object, ...])

Output a message on the console. If there are multiple parameters, these parameters will be separated by spaces during output.

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

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

Above example It can be replaced with the following unformatted placeholder output code:

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

And, these two methods are possible Used in combination. If formatting placeholders are used and the number of parameters provided is more than the number of placeholders, then the extra parameters will be appended to the end of 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 what is 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. You can use the formatting string %o to replace the Javascript object.

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

Formatted string list:

js console output method (detailed explanation)

console.debug(object[, object, ...])

at The console outputs a message containing a hyperlink to the location where the code was called. If you enter this command directly on the console, no hyperlink will appear (same as console.log()).

console.info(object[, object, ...])

Outputs a message to the console with an "info" icon and a hyperlink to the location where the code was called.

console.warn(object[, object, ...])

Outputs a message to the console with a "warning" icon and a hyperlink to the location where the code is called.

console.error(object[, object, ...])

Outputs a message to the console with an "error" icon and a hyperlink to the location where the code was called.

console.assert(expression[, object, ...])

Test whether the expression expression is true. If it is not true, a message will be written to the console and an exception will be thrown.

console.dir(object)

Outputs all properties of an object in list form, a bit similar to when you view a DOM window.

console.dirxml(node)

Output the XML source code of an HTML or XML element. Similar to what you see in the HTML window.

console.trace()

Prints an interactive stack trace of JavaScript execution at the point where it is called.

The stack trace details the functions on the stack, as well as the values ​​that were passed as arguments to each function. You can click each function to take you to its source in the Script tab, and click each argument value to inspect it in the DOM or HTML tabs.

console.group(object[, object, ...])

Output a message and open a nested block, and the content in the block will be indented. Call console.groupEnd() to close the block. This command can be nested.

console.groupEnd()

Close the last 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 (milliseconds).

console.timeEnd(nam)


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn