Scripts in a page will be executed immediately when the page loads. This is not always what we want. Sometimes we want to execute a script when a page loads, other times when a user triggers an event. Examples Head section Scripts that contain functions go in the head section of the document. Then we can be sure that the script is loaded before the function is called.
Body section Execute a script that is placed in the body section.
How to access an external script. Where to Put the JavaScript Scripts in a page will be executed immediately while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page loads, other times when a user triggers an event. When you place a script in the head section, you will ensure that the script is loaded before anyone uses it.