In the HTML file
When we use the first or the second way, we need to wrap our code inside script tags,
Our external JS script file /js/myscript.js:
Our HTML file index.html:
Over the three available ways, the 3rd one, usage of an external script file, is the preferable way.
One reason for this is because, this way, we separate markup from code. Moreover, it is easier to read the files and do changes. Also, it helps the page to load more quickly and we can share the same script file across multiple HTML files.
For more information: https://www.w3schools.com/js/js_whereto.asp