The <script> tag can go just about anywhere in the HTML code, in the <head> or <body> section, and will be executed as soon as the browser loads the <script> tag.
The following exercise shows how this works.
Practice Session #1
In the text editor of your choice, or in Dreamweaver Code view, open a new document. Save the document as practice1.htm.
Enter the basic HTML framework code (unless your program enters it for you). Your code should look like this:
<html> <head> <title>Practice Session 1</title> </head> <body> </body> </html>
Now move the <script> tag from the <body> to the <head> of your HTML document. Your code should look like this (new code in bold):
View the page in a browser again. You'll see that the result isn't much different from what you had before. The alert statement is actually being executed slightly sooner than it was before, because it's occurring slightly earlier in the codebut the entire page is loaded so quickly that there is essentially no difference.