<HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> <SCRIPT> document.write(Date()+".") </SCRIPT> </BODY> </HTML>
In the above, the code in the head creates a function called runClock (but doesn’t run it) – in the body, this function is called and runs, producing a clock on your browser’s status bar.
The difference between the function creation and function execution (as shown in the head and body sections) is similar to the difference between compiling and executing. The code in the head is designed to tell the browser that it will be used later – right now, just store it and keep it ready.
In the body, the command onLoad=”runClock” tells the browser that the function it stored earlier (‘compiled’) is now to be run (‘executed’). Usually, the majority of code will go in the head section – and it will often have the word ‘function’ near the front. There will always be a command referring to it in the body.