0

how document.write() and console.log() are different?

2nd Jan 2018, 1:43 AM
Abhishek
Abhishek - avatar
3 Answers
+ 4
document.write() puts text onto the webpage itself, while console.log() prints text to a JS console, which could be, for example, the Google Chrome Inspect console.
2nd Jan 2018, 1:45 AM
LunarCoffee
LunarCoffee - avatar
+ 1
document.write is used on an HTML page to display text on the screen. A more accurate and safer syntax is window.document.write( ) document.write is not recommended in modern programming because it has some issues, one of them being that it rewrites the page. It is a bit outdated. However it is still used a lot. innerHTML might be an alternative if done carefully. console.log is not really part of the JavaScript standard. It is an addition to JavaScript when JavaScript is used on a browser, specifically on a JavaScript console. 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. console.log is not really used in real life, in production code. It usually gets replaced by another command, one of them being your document.write.
2nd Jan 2018, 1:45 AM
Abhishek
Abhishek - avatar
+ 1
@lunar thank you for answering in short and precise way.
2nd Jan 2018, 1:46 AM
Abhishek
Abhishek - avatar