What is the difference between document.write() and console.log() in JS? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

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

2nd Aug 2017, 12:24 AM
Adrika
Adrika - avatar
3 Answers
+ 5
@noname: Technically, document.write() write not in <body> but in the document... meaning that you could write dynamically whole html source, and that in most of case, document.write() will implicitly open a new document overiding the actual content ;P To write specifically in <body> (or any html element) you need to get a reference to it and use its 'textContent' and/or 'innerHTML' properties ^^ @Adrika: On the other hand, console.log() is a method of 'console' object, which is independant of viewport main display (your web document), and it's mostly used at developing time as part of 'developer tools' provided in major desktop browsers: https://developer.mozilla.org/en-US/docs/Tools
2nd Aug 2017, 2:06 AM
visph
visph - avatar
+ 3
You might just want to try this in a CodePlayground code: console.log("Debugging zone"); document.write("DOM zone");
2nd Aug 2017, 1:37 AM
Kirk Schafer
Kirk Schafer - avatar
0
console.log outputs on the console. document.write writes in the document's body
2nd Aug 2017, 1:33 AM
voidneo