Scripts are executed in several different ways according to the context and environment in which they are run.
Script code enclosed inside <SCRIPT> tags in a web page is executed as the page is rendered or when the browser generates events. Some of the code (the global code) is executed as the page is loaded. Code contained in functions is called as it is needed, however it's probably a good idea not to call function code that is defined in <SCRIPT> tags within the <BODY> from global code that is in the <HEAD> of a web page. Some implementations may not mind but others may fail.
Some web browsers will allow you to access objects within the document while it is being built, others will only allow access to objects once the closing </BODY> tag has been processed. This suggests that there is some fixing up of the internal object referencing structures that is required before the DOM tree can be traversed. An example of this is the way that MSIE handles <DIV> and <OBJECT> tags. You may not reference an <OBJECT> tag from a script until the body.onLoad event. You can sometimes access <DIV> blocks after they have been created but before the </BODY> has been reached. This behaviour may be version-specific and also OS-specific and it may be that Macintosh and Windows versions of a browser behave differently. In the case of MSIE and Netscape Navigator, the rendering engines of both were rewritten at versions 5 and 6 respectively, and therefore many previous problems will be gone, only to be replaced by many new ones.
Scripts may be activated by a CGI interface when they are used in the middle-ware part of a server-side solution. These implementations will generally lack any kind of document model but instead will have a file system model and possible a means of reaching a database.
Scripts used in WAP phones provided a card and stack metaphor very like HyperCard. This is embodied in WML and WScript. The scripts are the mechanism by which the pages are presented to the user. They are transmitted in a compact byte-code form, which needs to be compiled before delivery.
In Navigator 2, when a window is resized, all the scripts in a page are executed again. You may not want this to happen.