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 Introduction to Programming Basics Comments

Console.log vs Prompt

This may be a very dumb question, but what exactly is the difference between console.log and the prompt function on Javascript?

2 Answers

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

The prompt() function opens a dialog box; a user can type a response in the box and that response is stored in a variable. For example:

var userName = prompt("What is your name?","");

console.log writes a message to a web browser's console. The console is normally hidden, so you need to open it to see the message. For example in Chrome you can open the console with Ctrl-Shift-J (windows) and Cmd-Option-J (mac).

console.log("Here's a message for the console.");

Thanks a million

Dave McFarland is there a way to run this all in the console so the prompt rather than being a popup is just a line in the console?

is console.log where a stored mini-program can be referred to over and over again eliminating the need to rewrite the min-program again and again?

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi cristina montanez

console.log is a command, also called a "function" or "method" that is programmed into most web browsers. You use the console.log command to write a message to the browser's JavaScript console.