document.write vs console.log JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 18

document.write vs console.log JS

when is it best to use document.write for output? why is it sometimes "best practice" to use console.log for output?

23rd Mar 2017, 12:20 AM
‎‏‎‏‎Joe
‎‏‎‏‎Joe - avatar
5 Answers
+ 17
"document.write is used on an HTML page to display text on the screen. ... console.log was created to make our life easier when we test our code. It logs to the screen the result we are looking for." Source: https://www.codecademy.com/en/forum_questions/53121d097c82ca0a33003906
23rd Mar 2017, 3:46 AM
Jafca
Jafca - avatar
+ 5
in my opinion console.log is for errors outputs
23rd Mar 2017, 5:20 PM
Irakli Samniashvili
Irakli Samniashvili - avatar
+ 3
you can use console.log to check if your script working right
23rd Mar 2017, 7:10 PM
vazha topchishvili
vazha topchishvili - avatar
+ 2
console.log , i usually used for debugging like printf in c while document.write used to display to the document created in html
23rd Mar 2017, 2:34 PM
Vinay Kumar
Vinay Kumar - avatar
+ 1
well, console.log() clearly states that it is logging to the console, whereas document.write() states it is writing to the document.
25th Mar 2017, 12:57 AM
Jacob Schneider
Jacob Schneider - avatar