Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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?
David Bath25,940 Points
Brian Hayes20,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.