I've put over 200 tips like that on my website: https://umaar.com/dev-tips/ Each tip has a textual explanation, and an animated gif if you're a visual learner (I know, I need to scrap gifs and move to regular videos). There's a lot of tricks there which can hopefully improve your development and debugging workflows. Let me know if there are specific things you'd like to see. A few people have asked for how to find me…
Use console.log() like a pro (2020)
41–50 of 156 posts
Re: Use console.log() like a pro (2020)
#42My whole personal site[1] is one big console.log(), right down to theme matching :D Unfortunately I'm not sure anyone has actually noticed. 1: https://itsokayitsofficial.io/
Re: Use console.log() like a pro (2020)
#43Earlier quoted context omitted.
I much prefer it being collapsed. When dealing with large objects, the firehose can be annoying.
Then, one day, after 12 hours chasing a race condition bug, you learn that when you expand objects from console.log, it shows you the current value of properties and not the values at the time of the console log. Because the values are evaluated when you click on the arrow. Then you quit web development and start a new career.
Re: Use console.log() like a pro (2020)
#44I used to think `console.log` was only good for soothing and assuaging the limbs of trees. Now I know better!
Re: Use console.log() like a pro (2020)
#45Earlier quoted context omitted.
Or you can console.log(JSON.stringify(x, null, 2));
I think you misunderstood the intent of the GP
Try this in a browser console: x={a:1,b:{c:1}};console.log(x);x.b.c=2;
then 'expand' the object, 'c' will be logged as 2, not 1
Re: Use console.log() like a pro (2020)
#46If you're using console.log to do debugging then it's worthwhile giving yourself a little more data to point at where a problem might lie - timings. Open up devtools (cmd+option+j), then open the command palette (cmd+shift+P), and then search for "console", and then select "Console - Show Timestamps". Now every console output will have the high definition timestamp prepended to it. That can be really helpful if you d…
Though you probably want the per-tab Console there (ctrl-shift-k). ctrl-shift-j would give you the multiprocess browser console, which is very noisy.
Re: Use console.log() like a pro (2020)
#47Rather than using %s, %i, %o, %f, etc. You can use a templated string, like this: `This is a string that has been printed ${someVar} times.`
Re: Use console.log() like a pro (2020)
#48I've put over 200 tips like that on my website: https://umaar.com/dev-tips/ Each tip has a textual explanation, and an animated gif if you're a visual learner (I know, I need to scrap gifs and move to regular videos). There's a lot of tricks there which can hopefully improve your development and debugging workflows. Let me know if there are specific things you'd like to see. A few people have asked for how to find me…
Re: Use console.log() like a pro (2020)
#49Wow there are some cool tricks here! In Firefox any objects you pass to console.log are expandable, so you can say console.log("my hash", h). It seems to behave the same when you say console.log("my hash %o", h). But there is a tricky thing that has really confused me in some debugging efforts: when expanded, the object display is "live", so it always shows the current properties of the object, not the properties as…
That's an anti-feature. When you log something in traditional sense you are recording something at that time.
I think it would be more confusing if the console did not work like the rest of the language does.
Re: Use console.log() like a pro (2020)
#50Wow there are some cool tricks here! In Firefox any objects you pass to console.log are expandable, so you can say console.log("my hash", h). It seems to behave the same when you say console.log("my hash %o", h). But there is a tricky thing that has really confused me in some debugging efforts: when expanded, the object display is "live", so it always shows the current properties of the object, not the properties as…
There's a more in-depth answer SO: https://stackoverflow.com/a/23392650