I am a novice, so I recorded it. This answer was seen on Baidu, so it is considered a reprint.
The following content answers what if the document.write is called after the page is loaded, it will overwrite the entire document.
The [HTML output] in the prompt refers to when the page is loaded.
The code copy is as follows:
<html>
<head></head>
<body>
<script type="text/javascript">document.write("<p>Hello</p>");</script>
</body>
</html>
When the page is loaded, you will see Hello on the page. Checking the source file is the code above.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
But if the page has been loaded and then use document.write, it will overwrite the entire document.
The code copy is as follows:
<html>
<head></head>
<body>
<script type="text/javascript">
// Call document.write when clicking the mouse
document.onclick = function() {
document.write("<span>Javascript</span>");
};
</script>
</body>
</html>
Because the mouse action is executed after the page is loaded, the entire page will be overwritten by <span>Javascript</span>. Now, you will only see <span>Javascript</span> when you look at the source file.