The following code can be placed anywhere in the html file:


// This is a very simple JavaScript statement that prints "Hello World!"
document.write("<h1>Hello World!</h1>");


The above example uses a single statement to write some markup to the document. The script is placed between opening and closing script tags.

The text in quotes (including the html tags) is written to the document by JavaScript using the document.write method.

Notice that the script includes a comment, which describes what the statement does. Single-line comments begin with a double slash "//".