T
5

Saw a comment that "console.log is not debugging" and it hit me hard

I was scrolling through a Stack Overflow thread about a JavaScript bug someone had. This senior dev just dropped that line as a reply. I've been using console.log for everything for like 8 months now. Actually spent 3 hours yesterday placing them all over a function trying to find why my array kept coming back undefined. Never thought about using breakpoints or the debugger tab. Has anyone else been stuck in the console.log trap and found a better way to step through code?
2 comments

Log in to join the discussion

Log In
2 Comments
riley595
riley5951d ago
Dude wait, THREE hours placing console.logs everywhere? That hurts just reading it. I was exactly the same way for like a year until my buddy walked over and showed me the debugger statement. Just type "debugger" right where you want the code to stop and it pauses at that exact line in the browser tools. You can hover over variables to see their values, step through one line at a time, it's a total game changer. No more deleting 50 console logs just to find the actual bug.
3
riley595
riley5951d ago
My first week on the job I had console logs everywhere across like six different files trying to track down a state bug. I had one that just said "hi" in the middle of a function because I forgot what I was even looking for at that point. Debugger statement changed my whole workflow honestly. Now I just drop one of those in and use the little arrow buttons to step forward line by line. You can see the call stack too which helped me understand why my functions were running in a weird order. Still use console.log for quick checks but never for the deep bugs anymore.
3