Better Programming

Advice for programmers.

Follow publication

Member-only story

Please Stop Using console.log() for Debugging — It’s Broken

Luc Claustres
Better Programming
Published in
4 min readFeb 27, 2018

Photo by chuttersnap on Unsplash

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…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Luc Claustres
Luc Claustres

Written by Luc Claustres

Digital Craftsman, Co-Founder of Kalisio, Ph.D. in Computer Science, Guitarist, Climber, Runner, Reader, Lover, Father

Responses (40)

Write a response

Although the Chrome Dev Tools are great, there are definitely some issues that cannot be found using it. One of which would be race conditions. I remember trying to use the the breakpoints trying to solve it, but it turned out that pausing the…

The title should be: "Please stop using console.log() for debugging, it's broken…"

This article comes off as artificial dogma, especially given that the author can’t even hold to his own premise.
There’s a reason you still use console.log() even though you claim to believe it is inferior — you are naturally gravitating towards the…