Home > Web Front-end > JS Tutorial > Console object parsing in JavaScript

Console object parsing in JavaScript

一个新手
Release: 2017-09-23 10:44:17
Original
1792 people have browsed it

Usually when using the browser's developer tools, I only use console.log(). Today when I was reading some information, I thought of taking a look at the properties and methods of the console object, and then I found that there are many things in the console that are convenient for us to debug. Method; briefly introduced below.

console.clear()

Clearing the console only clears the display and does not destroy the objects previously created in the console; after clearing the console, "Console was cleared”.


console.assert()

This method is used to determine whether the assertion is true. If it is true, there is no return value, otherwise it returns some self- Defined information; there are generally two ways to use it;
The first one: console.log(assertion, obj1, obj2, …, objn); assertion is a Boolean expression, and when it is false, the following objects will be output in sequence;

The second type: console.log(assertion, str); similar to the first type, but the second parameter here is of string type; an error will be reported when assertion is false;
Console object parsing in JavaScript

console.group () && console.groupEnd()
Copy after login

can make the printed information present a tree structure, and the information presentation is more clear and readable; console.group() is used to create a group, and console.groupEnd() is used to end a group;
Console object parsing in JavaScript

console.log()
Copy after login

This should be the most commonly used. In fact, it can also control the style and format the output like C language; supported formats include %d, %s, % f, %o, respectively represent integers, strings, floating-point numbers and objects (including integers, strings, floating-point numbers and other types); for style control, you need to add %c before the styled string, and then follow it with The specific style is given in the form of a string; the styles that can be set include font-size, color, font-style, text-decoration and other styles;
Console object parsing in JavaScript

console.table()
Copy after login

is the same as console.group It is all to make the information presentation more readable. The difference is that it is presented in table form; it can usually be used to print multi-dimensional arrays, JSON data, object objects, etc.;
Console object parsing in JavaScript

console.trace()
Copy after login

can be printed It shows the calling status of the stack when the function is running. I personally think this is very helpful for understanding function nesting, closures, etc.;
Console object parsing in JavaScript

The above is the detailed content of Console object parsing in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template