+ 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?

8th Jul 2018, 8:57 AM
Jepplo
Jepplo - avatar
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
8th Jul 2018, 9:05 AM
Ava 🐈
Ava 🐈 - avatar
+ 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
8th Jul 2018, 9:05 AM
Agent
Agent - avatar
+ 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
8th Jul 2018, 9:06 AM
KrOW
KrOW - avatar
+ 4
console.log is used for debugging
8th Jul 2018, 9:02 AM
Ben
Ben - avatar
+ 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.
8th Jul 2018, 9:32 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 2
Thanks everyone, I get it now!
8th Jul 2018, 9:35 AM
Jepplo
Jepplo - avatar