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

Chyno Deluxe
Chyno Deluxe
16,923 Points

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 ;)

Chyno Deluxe
Chyno Deluxe
16,923 Points

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?