1.3.3 External JavaScript File

To have JavaScript interact with the page, we need a place to put our JavaScript. While you can put the JavaScript code into a script tag right onto the html page itself, this is not ideal. Most developers put their JavaScript in an external file and connect it to the html page with a script tag like you have done with CSS…

In the above example, the JavaScript code would go in the script.js file. Note that most people put the script tag at the bottom of the html page. Why? It is because html, css and JavaScript is mostly interpreted vertically from top down. You want to ensure the DOM elements you are working with are loaded before interacting with them from JavaScript. Otherwise, you might run into undefined reference errors.