+ 3

What's the difference between document.write and console.log?

Hey, I did another tutorial on the internet and it told me to write console.log() when I want to show something. But here I see document.write. So what's the difference please? Thank you and apologize for my English

23rd Jan 2018, 11:00 PM
Greg Morak
Greg Morak - avatar
3 Respostas
+ 2
Hey Greg! In short, they're two different ways of manipulating the browser to show text, and you'll see both used a lot because they're easy for beginners to remember. So, here goes. The Document part of 'document.write' refers to the page in your browser, and everything that makes up the page (the JavaScript, HTML, and CSS). It's the big white space you want to make colourful and have fun with. Interestingly, the Console part of 'console.log' is actually a piece of the browser itself that hides in the background unless called upon (push F11 on your keyboard when the browser is open and the Console will appear!) When you use document.write, you are calling upon the 'write' method to override the existing code. It temporarily wipes the page clean and writes on the page, so all your code except for 'Hello, World!' disappears. Console.log calls upon the 'log' method, and it works in the SoloLearn playground too! It logs whatever text you've written to the console and does not affect your code. Basically, think of Document.write and Console.log like two siblings on a family tree. They give you the same result (Hello, World!) but in completely different ways.
24th Jan 2018, 4:53 AM
reinadf
reinadf - avatar
+ 3
document.write is a method that writes text right on your page, console.log is rather used to debug your code and it isn't part of website
23rd Jan 2018, 11:07 PM
ThreeG
ThreeG - avatar