+ 3
What is the difference between document.write() and console.log() in JS?
3 odpowiedzi
+ 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
+ 3
You might just want to try this in a CodePlayground code:
console.log("Debugging zone");
document.write("DOM zone");
0
console.log outputs on the console.
document.write writes in the document's body