Where is the correct place to insert JavaScript

Where is the correct place to insert JavaScript

The best way is to use an external JavaScript file which adds its own event listeners (a.k.a. unobtrusive JavaScript). The script file should be linked via a SCRIPT element inside the HEAD part of the web page.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
  <head>
    <title>...</title>
    <script type="text/javascript" src="/path/to/script.js"></script>
  </head>
  <body>
    ...
  </body>
</html>

It’s technically correct to insert SCRIPT elements in other places, too, but I wouldn’t recommend it since it ties the behaviour strongly to the markup.