There are two best working method to use script file

1 - if you have external javascript file then you link JS file  in the head by script  tag

Or Before the end of body tag by script tag  it work properly in both case

Example 01

<!---*********** This is index.html file ********---->

<DOCTYPE html>


<title> how use script file </title>

<!--************** attached external js file( index.js ) in head section  ****************/

<script src="index.js"> </script>



<p> Hey script tag working in both case </p>

<!--- ******you can also include external js file here*******--->



2 - If you have not external js file then you should write script before the end of body

Example 02


<p> use script in same file </p>


alert(" you can script code in here its working fine ");