Beyond console.log

Beyond console.log




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.

console.groupCollapsed
After click

console.groupCollapsed expanded



styling

Can use some CSS

console.log with CSS srcs



dir

Can log properties of an object with console.dir

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

console.assert



time

Can measure how long some operation takes with console.time

console.time



trace

Print a stack trace with console.trace()

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

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.