I am currently learning web development, and I'm currently learning JavaScript. And I have a question, where is the best place to put JavaScript (script tag) in the HTML?
Try to put all your JavaScript after your HTML code. The most common thing to see today is to place it in a separate file and use a script tag with a source file in it.
<script src='main.js'></script>
Or just placing it within the script tag. <script>..code..</script>
The reason that you need these tags after your HTML, so on the last line of your body, is so that when you need to get something from the DOM, you know it has been loaded in already.
Here is an Answer from the w3schools website:
JavaScript in <head> or <body> You can place any number of scripts in an HTML document. Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.