DEV Community

Discussion on: Stop Console.Logging! This is How to Use Chrome to Debug JavaScript

Collapse
 
smonff profile image
🌌 Sébastien Feugère ☔

Please edit « you are doing it wrong ». There is no « right » or « wrong » way to do it. This is a matter of preference. Both of the methods have pros and cons and it is unfair to declare console.log() wrong.

Collapse
 
jafuentest profile image
Juan A. Fuentest Torcat

You can write an article about the pros of console.log() but I don't think it's unfair to say that using one technique or the other is right or wrong.

Collapse
 
songthamtung profile image
songthamtung

Thanks for reading Sebastien!

Perhaps the better word instead of wrong is inefficient.

Quoting Google:

The console.log() method may get the job done, but breakpoints can get it done faster. A breakpoint lets you pause your code in the middle of its execution, and examine all values at that moment in time. Breakpoints have a few advantages over the console.log() method:

With console.log(), you need to manually open the source code, find the relevant code, insert the console.log() statements, and then reload the page in order to see the messages in the Console. With breakpoints, you can pause on the relevant code without even knowing how the code is structured.

In your console.log() statements you need to explicitly specify each value that you want to inspect. With breakpoints, DevTools shows you the values of all variables at that moment in time. Sometimes there are variables affecting your code that you're not even aware of.

In short, breakpoints can help you find and fix bugs faster than the console.log() method.

Collapse
 
nirmpate profile image
Nirmal Patel

I like using both. DevTools for more complex debugging where I want to understand the flow of my program. Console log for quick outputs of any variable that I want to see after I modify it. I don't have to go in and manually set a breakpoint and waste time stepping in and out and hovering over variables with my mouse to see what they are.

Collapse
 
avpaul profile image
Paul Abimana

Considering the fact that you have to go in chrome to find the sources and add breakpoints I find both ways to be the same in terms of what is fast.

Breakpoints or console.log, it is a matter of what you are debugging.

Collapse
 
appurist profile image
Paul / Appurist • Edited

The console logging functions have their place and for some tasks they are WAY more efficient than the debugger. For straight-up simple bugs and logic errors, yes, breakpoints and the debugger are key tools, but I definitely support the view expressed here that the title of this article is seriously flawed, along with the any suggestion that the console functions should in general be avoided, or are in some way inefficient. Generalizations like that should not be made.

Each approach is useful, and can be the most efficient, depending on the circumstance. Your article reads like "Don't use screwdrivers -- hammers are always more efficient." I find it misleading and poor advice, especially for novice developers who are clearly the target audience of the article.

I think the message is getting lost in this, and if the article and title was more like "If you use console.log to debug, here's another tool you'll want to add to your toolkit", it would be received a lot better.