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 Console Challenge Answer

Ruchika Roy
Ruchika Roy
833 Points

What is the difference between document.write() and console.log()?

Don't you usually use console.log() more often? In what situations would using document.write() be preferable to console.log()?

3 Answers

Jake Kobs
Jake Kobs
9,215 Points

document.write() is generally used in JavaScript to display the information on the webpage. So, if you were to do: document.write("<h1>Hello World!</h1>"); , Hello World! would be displayed on the website page as an h1 element. On the other hand, console.log() is great for programmer use. It can help with listening to events, which you will learn about later in the course.

Jake Kobs
Jake Kobs
9,215 Points

You're welcome! Best wishes on your tech degree journey!

Juan Guerrero
Juan Guerrero
3,994 Points

I wondered this myself. Thanks