+ 2

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

I figured out document.write supports html tags, but console.log doesnt...why? What's the difference between the two?

8th Jul 2017, 4:25 AM
Uziel ;) :) :p
Uziel ;) :) :p - avatar
1 Respuesta
+ 2
Hey Uziel, console.log prints to the console not to the window, like when you use Chrome Dev tools. The document.write method provides a way of incorporating strings into the HTML content of the page. There are better ways to do that, such as .innerHTML and .createElement or HTML cloning patterns. Use of document.write should be avoided. document.write is recklessly dependent on timing. If document.write is called before the onload event, it appends or inserts text into the page. If it is called after onload, it completely replaces the page, destroying what came before. document.write encourages bad structure, in which script and markup are intermingled. A cleaner structure has minimal interaction between markup and script. I hope this is helpful!
8th Jul 2017, 4:32 AM
deepak solanki
deepak solanki - avatar