I am a newbie, so I recorded it. This answer was seen on Baidu, so it is considered a reprint.
The following content explains why if document.write is called after the page is loaded, the entire document will be overwritten.
The [HTML output] in the prompt refers to when the page is loaded.
< ;/head>
When the page is loaded, you will see Hello on the page. View the source file which is the code above.
---------------------
But if the page has been loaded, use document.write again, That will cover the entire document.
< ;/head>
Because the mouse action is executed after the page is loaded, the entire page will be covered by
Javascript. Viewing the source file now will only see
Javascript.