Home >Web Front-end >JS Tutorial >Console object parsing in JavaScript
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.group () && console.groupEnd()
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.log()
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.table()
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.trace()
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.;
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!