So, you are always using console.log to debug your application, right?
In this post, I will show you alternatives to better debugging.
Int...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks man!
The % operator is like a placeholder.
Let’s say you have:
In this case, the second argument (“string”) will be replaced at
%s
.There is also a
%f
for float numbers, and it’s cool because you can do something like:You can do it the same way! You can use ... assignment and array of values in a
console.log
!Just like:
Both should work perfectly!
In the first example, my preferred method is normally the template string. I have trouble seeing the advantage of the
%
operator compared to concatenating the variables. Other than that, this article was useful and discovered me thedir
andgroup
methods!Yeah, I do not see a lot of advantages using % operator either, but I bring it just as informative content, it's a "good to know" thing...
Thanks! yesss,
dir
angroup
can be very helpful!The % syntax is for seasoned programmers who started with C and are now bald and wrinkly.
printf
still ringing a bell? 👩🏼🦲ahahaha
Great, thank you for this!
In your first example I think it is supposed to read
console.log('Hello ' + a);
Thank you!
Yes! You're right! That was my mistake! Just fixed it, thanks!!!
Mind blowing. Thank you for this article. Pity I always did console.log to dissect my objects and arrays. I think i going to overuse
console.table
now. :)You’re welcome!
It is really mind blowing! I have been using .log for years! Now I can debug stuff way faster!
Thanks for the article, console.trace() can be usefull sometimes.
Thanks!
True! I completely forgot about
console.trace()
, thanks for remind me!What does trace do?
Trace will show the stack trace, where that fails.
Let’s say in your app you have like a function that calls another function, that calls another function.
If you add a trace in the last function and something happen, it will log exactly where happened, like:
Oo! I like that one a lot. :)
First example can also be written as
console.log('Hello', a)
I few ones I didn't know like
console.dir
. Thanks for this!You're welcome!
Sorry for the dumb question but do you need a certain console for this to work? I tried both the CSS and grouping things after updating to the latest version of node and neither works. What am I missing? I'm on a Mac using the Terminal app.
Oh, I’m not sure how it works on node, if node has some limitations, but, my examples were all done by any web browser console (developer tools)
Oooooooooh! Haha. I totally assumed the node terminal. That makes a LOT more sense now. Thanks for the fast reply.
ahahaha! you're welcome!
Hey guys, I have been working on my very first APIs project and in that project I'm making a "QUIZ APP", where from an API. I have been taking 10 question and giving them multiple choices and at end they will be getting scored. I'm using NODE.JS, EXPRESS, REQUEST, EJS for the app.
The problem comes here when i get a string from API. I change it to an object using JSON.parse() and sending it to EJS files and then displayed. but when their are symbols in question like ", ' , and more they are displayed as &139; , " like that.
These days, I use this a lot:
console.log({ a, b });
That's awesome and very useful! I'm using that a lot though!
I've authored a tiny utility to easier styled console logs:
github.com/yairEO/console-colors
That’s cool!!
Great and usefull article!! thanks!!
console.table open my eyes!!
i will use it when i receive json response and i need to view results.
Super useful, thanks for this Guilherme!
You're very welcome! I'll probably bring more useful things here soon!
Thanks for sharing, Guilherme.
You’re welcome!
Useful info! Thanks :)
You're welcome man!
awesome tips!
Thanks man!
console.time also worth to mention!
Apart from that nice and concise article
That's true! console.time also worth the search! Good mention
Thanks for the article.. Its really awesome..
I never knew console had these many methods.
You’re very welcome!
Yep, console has so many things that can help us, developers!
I never knew about console.table. Thanks for the great article!
You're welcome man! Yep, some console mysteries were revealed 👀
This was great, thank you! So nice to have options to console.log(), this will make it much easier to debug!!!
You're welcome!
Loved it! Very informative