+ 3
console.log or document.write
I've tried to learn Javascript on codeacademy, and they use console.log to get outputs like "hello world" etc. But SoloLearn uses document.write. document.write feels more correct based on its name, but is there a real difference?
6 Answers
+ 15
Console.log outputs to the console whereas document.write outputs to the web page. They have different uses depending on the situation
https://code.sololearn.com/W6oFL6ixrxv0/?ref=app
+ 5
document.write is normally used
console.log is used for
testing as
Benjamin said.
It used with the console so you can see how the page works
Here is what codeacemy says:
https://www.codecademy.com/en/forum_questions/53121d097c82ca0a33003906
+ 5
document.write put your text onto page, console.log (and related) dont but you can see it on browser that support console (almost all)... Like Benjamin tell you, latter its used for debugging and make notes to devs
+ 4
console.log is used for debugging
+ 3
If you are talking about using Javascript to form a webpage. Both console.log and document.write are not the correct ways to do it.
console.log are reseaved for debugging only. And document.write is for one time only update to webpage, which web developer would not use it.
To be a real web developer, learn to use document DOM update functions eg. getElementById, getElementsByClassName and querySelector, to update your Javascript data onto webpage together with other HTML and CSS, and only use console.log to debug or test any js variables.
+ 2
Thanks everyone, I get it now!