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.
Can anyone explain to a beginner what console.log does?
console.log does. I think I understand that
console.log stores the data that the person enters, but where? An example:
var visitorName = prompt("what is your name?"); //alert (visitorName); console.log(visitorName);
console.log() is a function that prints to the terminal (or console) whatever parameter it's been given. It doesn't store information so much as simply take in data and print it.
You can also use console.log to print directly (without using a variable), like:
console.log("Here's my string!");
Hope that helps clarify a bit.
Cena Mayo's explanation is pretty solid. I would just add, that most people use console.log() to check and see if their code is working. Like in the example you have, you are alerting the variable visitorName, and you are printing the variable to the console. they should both match up. this is one way to know that things are working as they should.
Nicholas Grenwalt46,626 Points
To add to Cena's great explanation, the console isn't something that gets displayed to the web page for a user to see, but is rather a tool used primarily by developers for testing to make sure that sections of their code are running as they had planned.