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')
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.
styling
Can use some CSS
dir
Can log properties of an object with console.dir
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
time
Can measure how long some operation takes with console.time
trace
Print a stack trace with console.trace()
clear
Clear things up with console.clear()
Related
Check out great old post – https://dev.to/lissy93/fun-with-consolelog-3i59
Source link
lol