+ 2

When should document.write and console.log be used?

6th Dec 2020, 3:18 AM
Priyanshu Sharma
Priyanshu Sharma - avatar
9 Réponses
+ 2
The console.log() method writes a message to the console.The console is useful for testing purposes. While the write() method writes HTML expressions or JavaScript code to a document. The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML.
6th Dec 2020, 3:41 AM
Priyanshu Sharma
Priyanshu Sharma - avatar
+ 6
Priyanshu Sharma hello,if you want to know in detail then you can visit this sites Document.write method https://www.w3schools.com/jsref/met_doc_write.asp Console.log method https://www.w3schools.com/jsref/met_console_log.asp
6th Dec 2020, 3:26 AM
ㅤㅤㅤ
+ 6
Priyanshu Sharma Good answer! but try to use try google for this common types of questions... Many websites and Youtube Tutorial available you can know in detail from there.
6th Dec 2020, 3:48 AM
ㅤㅤㅤ
+ 5
document.write("this is write"); console.log("this is log"); Copy paste in javascript section of html code and see the effect
6th Dec 2020, 4:36 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
ᕙ(@°▽°@)ᕗ Ok Thank you... I got it.
6th Dec 2020, 3:39 AM
Priyanshu Sharma
Priyanshu Sharma - avatar
+ 2
document.write() gives new learner a feel of how JS affects the DOM of the page. As a developer however I advise to use the methods of console. Not only log() exists but many others and each has it's own helpful function
7th Dec 2020, 9:00 AM
Coal
+ 1
Царь СОБАКА - Догго I So if we use document.write then the existing html output will be over written by the document.write... Is that what you say
6th Dec 2020, 3:26 AM
Priyanshu Sharma
Priyanshu Sharma - avatar
+ 1
And if we use console.log then where we get the output as it will be displayed in the console... I didn't get it please explain...
6th Dec 2020, 3:28 AM
Priyanshu Sharma
Priyanshu Sharma - avatar