Home > Web Front-end > JS Tutorial > Beyond console.log

Beyond console.log

Mary-Kate Olsen
Release: 2024-12-06 18:56:18
Original
452 people have browsed it

intro

As much as I hope that things will always work from first try, better to be prepared to debug it. console.log remains the main tool to do it, because it is the simplest and fastest.

Few console methods are known to everybody, log, warn and error.

Going deeper

There are more tricks to it.

count

For example, if you need to count how many times component re-render can use console.count, e.g. console.count('comp1')

Beyond console.log

group and groupCollapsed

Can log some info in a collapsed group with console.groupCollapsed, great in case of many error messages, when they printed collapsed it's less distracting, but Node.js/Sentry probably will print all expanded.

Beyond console.log
After click

Beyond console.log

styling

Can use some CSS

Beyond console.log

dir

Can log properties of an object with console.dir

Beyond console.log

objects

Can log few objects with curly braces like console.log({ obj1, obj2 }), instead of console.log('Ojb1', obj1)

assert

Can assert things with console.assert

Beyond console.log

time

Can measure how long some operation takes with console.time

Beyond console.log

trace

Print a stack trace with console.trace()

Beyond console.log

clear

Clear things up with console.clear()

Related

Check out great old post - https://dev.to/lissy93/fun-with-consolelog-3i59

The above is the detailed content of Beyond console.log. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template