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! While you're at it, check out some resources Treehouse students have shared here.

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

JavaScript JavaScript Basics (Retired) Introducing JavaScript The Console Challenge

Aimee Cruz
PLUS
Aimee Cruz
Courses Plus Student 1,824 Points

console.log()

I don't really understand what the purpose of the console.log() is. Why do we need to implement it inside the script tag

5 Answers

It's been a while since I've completed this track so I am not sure why but I can only make a guess that its to verify that the document is loading correctly. If the console.log() message shows up in the console then that lets you know that the .js file is working properly.

I hope this helps.

Chyno is right (it helps us know that the program is working correctly when debugging). In this example program, the console.log() function isn't really necessary/useful at all (I'm not trying to knock the example or the instructor with my comment - I think Dave McFarland is great and that in this example he's just trying to get us in the habit of using it to debug).

Later on, console.log() is really useful if we have a much longer script by displaying values in variables (it can quickly show us if we made a math mistake or other mistakes that aren't obvious). We could use alert() to do the same thing when we're debugging, but console.log() is less annoying to if you have to print a bunch of messages ;)

console.log() is used for debugging and testing. It's not something the average user will see.

Aimee Cruz
PLUS
Aimee Cruz
Courses Plus Student 1,824 Points

Got it. But why do we need to include the console.log() inside the actual .js document if the console is only for debugging and testing?