From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Move JavaScript to an external script

Move JavaScript to an external script

- So now we have a basic JavaScript program that runs inside the browser. However, it's quite a bit of clutter to have all of this JavaScript code inside the index.html file. So what we can do, and what we're going to do in this video is move all of this code out into an external script. And this is a fairly straightforward process. All we have to do is create another file and we'll call that file something like generateTable.js. And then we're simply going to take all of this code that we defined inside the script tag here, and cut, and paste it into our generateTable.js file. And now all we have to do is, instead of defining our code inside the script, we are going to have a script tag. But this script tag is going to have a property that says SRC equals, and then the path to the JavaScript file that we want to import. So in this case, it's generateTable.js. And now if we go back to our browser and refresh it, we'll find that we can run our code again. Except now all of our…

Contents