Statements
JavaScript is a sequence of statements to be executed by the browser. These statements are commands to the browser and they are executed in the order in which they are written. The browser intreprets these commands and performs the action.
The following example shows JavaScript code that writes Heading and Paragraph text:
<script>
document.write("<h1>Heading Text</h1>");
document.write("<p>Paragraph Text</p>");
</script>
This produces the following result:
Blocks
JavaScript statements can be grouped together in blocks by surrounding the statements with curly brackets. Generally, statments are placed into blocks so that they can be executed together, like in a function or in a condition.
The following example shows the same JavaScript code as above, but grouped together in a function block:
<script>
function message()
{
document.write("<h1>Heading Text</h1>");
document.write("<p>Paragraph Text</p>");
}
</script>
It is important to note that this could would only execute if the function message was called from other script code.