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

question

teacher, i watched your videos about console log . but how do we use console.log syntax we only just type (console.log("start program") (console.log("end program") is this is the use of console.log syntax?

1 Answer

console.log("string"); //log out this specific string
console.log(variable_name); //log the output of a variable
console.log(2+2) //solve an equation

In your particular example it looks like they were using console log to show when a process started and when it completed. Since javascript runs sequentially it will ensure that if "program end" appears in the console that everything finished running.

function foo() {
   console.log("program started");
   //do things here.
   alert('FOO!');
   //if everything has finished successfully
   console.log("program end");
}

If you don't received program end, you know that something broke down and can begin troubleshooting. I primarily use console.log when troubleshooting to try and figure out where I'm getting stuck or why something isn't working.