js Console object-Kaiqisan

js Console object

ヤッハロー, Kaiqisanすうう, 一つふつうの学生プログラマである, Yesterday, when playing webstorm, after typing in the console., it automatically popped up many other methods. With a curious mind, I checked some information and discovered the new world. ~

The Console object provides information to access the debug mode of the browser to the console.

method description
assert() If the assertion is false, the error message will be output to the console.
clear() Clear the information on the console.
count() Record the number of count() calls, generally used for counting.
error() Output error information to the console (manually report errors)
group() Create an information group in the console. A complete information group starts with console.group() and ends with console.groupEnd()
groupCollapsed() Create an information group in the console. Similar to console.group(), but it is collapsed by default.
groupEnd () Set the end of the current information group
info() The console outputs a message
log() The console outputs a message
table() Display the data in tabular form (really draw a table in the output column, it is best to display arrays and objects)
time() The timer, which starts counting time, is used in conjunction with timeEnd() to calculate the exact time spent by an operation.
timeEnd () Time ends
trace() Shows the call path of the currently executed code in the stack.
warn() Output warning message, with a yellow triangle at the top of the message, indicating warning (warning can be done manually)

The above table information comes from the rookie tutorial

Examples of use of some methods

console.time(val)And the console.timeEnd(val)internal parameter is the name of the timer, which is the only standard for distinguishing console.timeEnd(val)the timer, and the name of the closed timer also needs to be specified

console.time('a') // 开始计时
/// 待执行的代码
console.timeEnd('a') 	// 这里会输出执行完成上面代码所消耗的时间

PS: When a timer is turned on, you cannot start the second same timer again , otherwise a warning will be reported. Or if a timer that is not currently running is turned off, a warning will also be reported

console.time('a') 
console.time('a') // 这样不行

console.group(val), console.groupCollapsed(val), console.groupEnd()Collected from console.group()or console.groupCollapsed()begin to console.groupEnd()encountered during the integration of all print all information, val in brackets can pass values to name the group's name.

console.group('apop')
console.log('a')
console.log('a')
console.log('a')
console.log('a')
console.log('a')
console.log('a')
console.groupEnd()

group
You can also click to collapse or generate a secondary list

but

This method is a synchronous method. It will not wait for the execution of the asynchronous function during the period . It is recommended that if an asynchronous function is encountered, it should be console.groupEnd()written in the callback function after the completion of the asynchronous function (then() catch()).

console.assert(val): Determine whether the internal output content is true, if it is true, do not output, if it is false, report an error

Assertion failed: console.assert

count(val): The call starts counting, the internal parameter val is the name of the counter, and different names represent different counters.

console.count('s')
console.count('s')
console.count('s')
console.count('s')
console.count('d')
console.count('d')
console.count('d')
console.count('d')

Output is

Insert picture description here

PS: The name of the counter must be a string . If other types of data are passed in, it will be implicitly converted to a string type.

to sum up

With this, don’t just use console.log()it. So many convenient tools are very conducive to development. It is recommended to remember that they are very practical, and children like them very much. They have been used 100 million times.

Guess you like

Origin blog.csdn.net/qq_33933205/article/details/108102368