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 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.