console.log()
can be used not only for logging, but also for several other useful operations. I chose the 5 most interesting ways to use the Console, suitable for everyday life. > console.assert(document.querySelector('body'), "Missing 'body' element") > console.assert(document.querySelector('.foo'), "Missing '.foo' element") [Error] Assertion failed: Missing '.foo' element
console.table()
, I recommend reading Marius Schultz ’s article “Advanced JavaScript Debugging with console.table ()”console.profile(name)
outputs the processor load to the console. You can use the report name as an argument. Each launch is saved in a separate tab of the drop-down menu. Do not forget to close the report using console.profileEnd()
.console.group(message)
groups all logs after themselves until receiving the console.groupEnd()
command. Lists can branch. console.groupCollapsed(message)
works in a similar way, the only difference is in the display.console.time(name)
starts a timer with the name specified in the argument, which counts the time until it is stopped by the command console.timeEnd(name)
. Of course, in both functions you need to use the same name. > console.time('Saving user') > console.log('User saved') > console.timeEnd('Saving user') Saving user: 2.750ms
Source: https://habr.com/ru/post/253081/
All Articles