JS, can someone explain the difference.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

JS, can someone explain the difference..

there are console.log and document.write what is the difference between them, and why when you write document.write instead of console.log this is considered a bug in the code trainer? im so tired of it, i dont get it 😭😭😭

8th Jan 2023, 10:34 AM
lilchicha
lilchicha - avatar
1 Answer
+ 7
console.log() writes a log message into the Javascript console instead of the document/page. document.write() overwrites the content of the document that is currently loaded. Its usage was considered bad practice because it overwrites/replaces the page content entirely. It is considered better to update parts of the document e.g. to change an element's text or value (or other attributes as necessary) rather than to overwrite everything.
8th Jan 2023, 11:10 AM
Ipang