DEV Community

Cover image for Use console.log() like a pro

Use console.log() like a pro

Marko Denic on November 23, 2020

Using console.log() for JavaScript debugging is the most common practice among developers. But, there is more... The console object provides acces...
Collapse
 
stegriff profile image
Ste Griffiths

Great post!

I'd add that you can console.log a few things, separated with commas, and they will come out with their "native" formatting instead of the dev tools trying to change them to strings. Sometimes this is better than using the string substitutions, and it's better than concatenating them with +

Example: Example

Collapse
 
denicmarko profile image
Marko Denic

Great addition. Thank you, @stegriff .

Collapse
 
blossom profile image
Blossom Babs

This is a great hack! I didn't know half of this before now. Thanks.

Collapse
 
denicmarko profile image
Marko Denic

Thanks a lot @blossom !

Collapse
 
ayabouchiha profile image
Aya Bouchiha

Good job 🤗

Collapse
 
denicmarko profile image
Marko Denic

Thanks a lot!

Collapse
 
onyxcode profile image
Dan

I've been wanting to know how to do those custom CSS styles! Thank you!

Collapse
 
denicmarko profile image
Marko Denic

My pleasure, @onyxcode . Glad you like it.

Collapse
 
mathewthe2 profile image
Mathew Chan

Good post. Didn't know about console.assert. But as someone once told me, you must remove all your console logs before you commit :)

Collapse
 
denicmarko profile image
Marko Denic

Haha, that's true @mathewthe2 . I sometimes forget to do that.

Collapse
 
shookcodes profile image
Sarah Shook 💎

Thank you for sharing this article, so many great uses of console.log() I haven't explored yet. I'm especially excited about console.clear()!!

Collapse
 
denicmarko profile image
Marko Denic • Edited

Thanks, @joojaco . My personal favorite is the console.table(). I'm so glad you liked the article.

Collapse
 
jainpawan21 profile image
Pawan Jain

I found console.table() quite interesting.
Thanks for sharing cool stuff.

Collapse
 
denicmarko profile image
Marko Denic

Glad you like it @jainpawan21 . :)