JavaScript JavaScript Basics 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,212 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,212 Points

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

Juan Guerrero
Juan Guerrero
3,994 Points

I wondered this myself. Thanks