It is important to note that document.write should only be used for testing purposes, as it can cause unexpected results when used in a live environment. Additionally, document.write should not be used to insert content after the page has finished loading, as this can cause the page to reload and overwrite any existing content. For these reasons, it is best to use other methods, such as innerHTML, to insert dynamic content into a page.
The code above would insert an h2 header with the words “Hello World!” into your page. Keep in mind that it must come after the same element in your page’s code and can not be used to insert content between elements.
It is important to note that document.write will overwrite any existing content on the page, so it should be used with caution. Additionally, document.write will not work if it is called after the page has finished loading. For this reason, it is best to use document.write at the beginning of your script block.