As a rule of thumb, JavaScript (JS) files should always be included at the end of the document. Most of the times the JS will interact with elements on the page. Putting the JS at the bottom of the document will reduce the chance that an element that is to be interacted with does not exist. JavaScript can be included from an external file, or placed directly inside the document. The former is in general preferred because it increases maintainability and reusability. Directly in the document:
<html>
<head>
</head>
<body>