DEV Community

Alex
Alex

Posted on

2

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')

console.count

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 styles

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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay