You can place the <SCRIPT> tag in the <HEAD> or <BODY> section of the page.
In the <HEAD> context, it is expected to provide some support to the rest of the page so you might place useful functions and event handlers here. You can also put some global code here and it will get executed inline, probably initializing some global variables. The intent is for the <HEAD> block to contain only meta-information about the document. This implies you should not place a document.write() method into the <HEAD> area such that it will be executed during page loading. However, both the Netscape and MSIE browsers will allow the document.write() if it is called during page loading even if it is located in the <HEAD> block.
It makes some sense to be sure that if you do a document.write() in the <HEAD> block, that you make sure it writes something sensible. For example, you can write the document title from a script that is executed inline. If you just write some textual output, the browsers are at least smart enough to place it into the page body.
You can place <SCRIPT> tags throughout the <BODY> of the document. These might also contain functions but are more likely to contain inline code to be executed as the page is loading. Although they are in different <SCRIPT> tag blocks, they are all conceptually part of the same script.
If your inline script code is going to do any document.write() calls to modify the HTML as the page is loaded, then this is the optimum place to put the code. It's quite sensible to break the code into smaller <SCRIPT> blocks and place them appropriately throughout the document. If the code starts to become complicated, then factor some of it into functions placed in the <HEAD> area and then call it as needed from the <BODY> area.
If you are using a frame-set, you can put the <SCRIPT> block after the <HEAD> tag but before the <FRAMESET> tag. You could write the entire <FRAMESET> description at this point using document.write() methods. You could do that with the entire <BODY> content too.
When the browser encounters a <SCRIPT> tag, it pauses the processing of the HTML page description and executes the <SCRIPT> tag's source code. That may affect subsequent HTML output anyway, and may generate some HTML to be placed into the page at the point where the <SCRIPT> block appears. Any lengthy script evaluation is going to slow down the display of your page. You should defer any lengthy processing until you can use some sleight of hand to hide it. For example, perhaps you can wait until the <BODY> tag is closed and then activate some processing with a <BODY ONLOAD="..."> handler. This may be an issue if you are using included .js files since they will need to be requested and fetched from a web server.
You can build event handlers and associate them with the event by means of the <SCRIPT> tag attributes, but this only works in MSIE.
Be aware that if you place <SCRIPT> blocks inside the <HEAD> of a document, you may be able to initialize some data structures but you certainly won't be able to access any objects that belong to the <BODY> since they won't yet exist.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> myResult = 100; myExpr = myResult %= 1000; document.write(myResult); document.write("<BR>"); document.write(myExpr); document.write("<BR>"); </SCRIPT> </BODY> </HTML>