Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0

console.log is a legitimate debugging tool

I've used breakpoints, profilers, and all the fancy devtools. But when something breaks at 1 AM, my first move is still: console.log("here"); console.log("here 2"); console.log("WHY IS THIS UNDEFINED"); It's not

I've used breakpoints, profilers, and all the fancy devtools. But when something breaks at 1 AM, my first move is still:

console.log("here");
console.log("here 2");
console.log("WHY IS THIS UNDEFINED");

It's not pretty, but it works. Here's what I've noticed over time:

  • Writing a log forces me to state what I expect. To log a value, I first have to decide what it should be at that line.
  • It works everywhere. Every language, every stack, zero setup.
  • The bug often shows up while I'm typing the log. Half the time I find it before running anything.

Where it stops working

The rule I follow now: if I've added more than 5 logs, I'm guessing, not debugging.

At that point the logs have stopped answering questions and started adding noise. That's the moment to stop and step through the code with a real debugger, where I can inspect state, watch the call stack, and see exactly where the value changes.

Print debugging isn't the problem

Used on purpose, console.log is a fast way to test a hypothesis. The trouble starts when it replaces thinking.

Print debugging isn't the problem. Not knowing when to stop is.

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.