Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Introducing JavaScript The JavaScript Console

Javascript Console as Explained by Dave Seems Completely Inefficient as a Debugging Tool...Am I Missing Something?

In the JS Console Introduction video Dave mentions briefly that the console only displays 1 error message at a time. He mentions that if your code is 100's of lines long something like: you'll be glad that the console pinpoints the location of your error.

However if you only get to display 1 error at a time in a huge program, regardless of the console's ability to pinpoint the location of the error, isn't that horribly inefficient? Doesn't a code editor like Notepad ++ also highlight errors but allows for more than 1 error to be shown at a time?

In other words, when would using the console be an efficient way to debug a program?

2 Answers

David Bath
David Bath
25,939 Points

JavaScript will fail if there is an error, so knowing where that error happens is important and the console may even tell you the line where it occurs so you can fix it. But not only that, you can also log out messages at various places in your program that will let you know that a particular function occurred, and also what values variables hold at that point in the logic. This can be tremendously helpful. A code editor might be able to highlight errors like missing braces, but not much beyond that.

Brian Hayes
Brian Hayes
20,986 Points

The console can be a good debugger to use as you go, however, there's a lot more you can do. Some of what you're talking about, with basically checking the syntax of your code, can be done with linting in your text editor of choice, and then there's doing unit testing and the like. The last time I was working on a bigger bit of code, I ended up writing an object for the sake of debugging. It's various methods would allow me to output values and function returns throughout my code to the console so i can really see exactly what's going on. The other nice thing about using a separate object with methods that i end up calling in other objects or functions in my project, is that I don't use console.log all over the place, which i would have to remove before my code goes to production. With a debug object I can just have a property that has a boolean value to that has to get checked before its methods execute their functionality... so basically i have a "debug mode" i can turn on and off.

So really, I guess my point is that there are a lot of ways to go about debugging, and the console can really help with that, but it just comes down to how you go about using any of it.