+ 1

document.write() VS console.log()

While browsing through some other Javascript material, I saw console.log() used instead of the regular document.write() used here in Sololearn. Please in case are they applicable or can they be used interchangeably?

1st Jul 2017, 7:33 PM
Chris Cypher
Chris Cypher - avatar
2 Respostas
+ 4
document.write() is for modifying HTML content, and console.log() is for outputtibg to the console.
1st Jul 2017, 7:46 PM
Keto Z
Keto Z - avatar
+ 2
Okay. I get it now. In that case, I think it's preferable to output to the console instead since it won't affect the markup. Document.write() might unintentionally wipe up existing HTML content.
1st Jul 2017, 8:03 PM
Chris Cypher
Chris Cypher - avatar