News for hackers. Stuff that matters.
Re:Advanced console.log Tips and Tricks (2020) by onion2k on Tuesday June 15, 2021 @11:25PM (#27524551)
Practically every time I do a 'console.log' to see the value of something in the current page state I actually wanted a 'debugger' statement instead. Pausing execution so I can look at other things around what I wanted to log often proves very useful and let's me get to the root cause of a problem faster.
Re:Advanced console.log Tips and Tricks (2020) by MindTwister on Wednesday June 16, 2021 @02:14AM (#27525415)
Are you lamenting that you reach for `console.log` first, instead of using the `debugger` statement, or are you wishing there was a `debugger` statement, because there absolutely is a `debugger` statement. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:Advanced console.log Tips and Tricks (2020) by onion2k on Wednesday June 16, 2021 @04:16AM (#27526138)
I'm lamenting that I reach for console.log first and then regret it. Every single time.
Re:Advanced console.log Tips and Tricks (2020) by mrblampo on Wednesday June 16, 2021 @06:28AM (#27526891)
Huh, why do you think you do that? Do you forget about the debugger statement, or is there some other reason you think console logging might work well?
Re:Advanced console.log Tips and Tricks (2020) by mrblampo on Wednesday June 16, 2021 @06:31AM (#27526900)
Maybe my debugger skills aren't strong enough, but I find that when I'm trying to reason about how some complicated code is executing, a debugger statement forces me to wade through tons of internals in libraries I don't care about. Some well-placed console logs give me much less information overload.
Re:Advanced console.log Tips and Tricks (2020) by bryanrasmussen on Wednesday June 16, 2021 @09:02AM (#27528034)
The same here, also in my case at least 90% of the time when there is a problem I know where the problem is I just need to look at a couple things and confirm which of a couple scenarios could be causing the problem.
Re:Advanced console.log Tips and Tricks (2020) by Griffinsauce on Wednesday June 16, 2021 @01:30AM (#27525220)
This is really missing at the moment.

I wish there was a "debugger snapshot" functionality that does not pause execution and creates a snapshot of the current DOM and state.

Probably a performance nightmare but being able to continue and inspect what happened in retrospect is what makes console.log a powerful debugging tool IMO.

You could extrapolate this to the time-traveling debuggers we've seen for Redux and other tools. That stuff is super powerful.

Re:Advanced console.log Tips and Tricks (2020) by hibbelig on Wednesday June 16, 2021 @09:56AM (#27528536)
Interesting. I feel the opposite. Reading through multiple log lines somehow tells me something about the problem (program) that I don’t get when I use the debugger.
Re:Advanced console.log Tips and Tricks (2020) by jansan on Wednesday June 16, 2021 @05:55AM (#27526700)
console.log(JSON.stringify(myValue, null, 2)) could be what you are looking for.
Re:Advanced console.log Tips and Tricks (2020) by onion2k on Wednesday June 16, 2021 @06:00AM (#27526732)
That's just a prettier console log. I almost always want to use the debugger.