2. Generating output

2.3. Output to the Browser Window


          The most convenient output statement to use when testing your code is the document.write().  The output is displayed in the current document.

Sample Code:


          If the method document.write() is used after the page has been loaded, it will overwrite all the existing content in that document. If you try the sample code below, you will notice that it displays the content of h1 and p. It also has a button with a label “Click me”. Once you click the button, it refreshes the page and overwrites its display with the text “Hello World!”.

Sample Code: