Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Browser debuggers are amazing. I've been using them since Venkman. There's no substitute for setting a breakpoint, via the UI or a `debugger` statement, and watching your code execute a line at a time, in context. But that doesn't make console.log() a bad practice! The console is a great tool I am glad to have, especially when I remember the alternative, which was calling alert() and getting [object Object] and wanting to throw your desktop tower out the nearest window.


Use console.log for it's intended use, formatting string output, but for debugging purposes, it is a bad practice because the reason it's used usually do not usually justify the sloppy unfocused mess it leaves behind. A poorly written log statement is tech debt, as well. Debugger provides all the benefits one would expect with console.log usage:

1. You can see where you are at that moment of execution in code

2. You can see variables and arguments within scope

3. You can forget about it and a linter will pick it up or it will be ignored unless run in debugging mode

All of this allows you to focus on the actual bug and not looking for something like:

`MY SPECIAL VAR: [object Object]`

I forgot to format, let's run it again.


What about your workflow causes console.log statements to litter the code but not debugger statements? There are fewer of them?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: