You can place all your scripts into an external file (with a .js extension), then link to that file from within your HTML document. This is handy if you need to use the same scripts across multiple HTML pages, or a whole website.
src attribute to the HTML
The code in your .js file should be no different to the code you would normally have placed in between the script tags.
But remember, you don't need to add the
<script> tag again — it is already on the HTML page calling the external file!
<body> tag. This allows the rest of the page to load first, before making the call to the external file.