Member-only story
Please Stop Using console.log() for Debugging — It’s Broken
Why it’s broken and how to do better

Adding console.log()
to our code is probably one of the most common practice among developers. However, I have spent a lot of time in my life to persuade beginners (and sometimes proficient coders) to stop using it for debugging JavaScript. Here’s why.
First, I must admit that I’m still doing console.log()
statements in my code — old habits die hard. I’m not alone: Around 75% of Node.js developers report using it (in 2016) for finding errors in their applications.
In a couple of situations it is either the simplest thing to do because you know exactly what and where to log information, or it’s the only thing to do because you are in constrained production/embedded environments with no other tool. However, this not an excuse to make the exception lead your daily practice. Indeed, as a general rule, console.log()
is painful and prone to errors — as you will see hereafter. There are much more sophisticated solutions available.
Missing Contextual Information
console.log()
forces you to consciously select which information to be logged prior to debugging. And what you display in the first place isn’t sufficient or even completely irrelevant because you usually don’t yet have any idea of what’s going on.
Every time you launch your app, you go a step further — whether it be realizing you’re still not logging the right information at the right time or wasting hours changing your statements again and again to display new information and hide irrelevant info.
Counterattack with a debug tool:
- Display/watch any JS variable inline while debugging (function arguments, local variables, global variables, etc.)
- Explore the call stack to get the complete context in which your problem appear
Too Much Information
Algorithms are usually designed to automate a large number of small tasks — loops and recursion being fundamental building blocks for this. Along with console.log()
, it results in a large number of lines displayed in front of you, so you may have a hard time coming to…