var y = 2;
alert ("Hello World!");
Script in headThis script will be executed when called (usually in the form of a function) or called based on a trigger at certain events. Putting the script in the head will ensure the script is loaded before being called.
<script src = "file .js"></script>
<p> The above script is in the "file .js" (external) file </ p>