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 - JavaScript Tutorial
From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
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
-
-
-
-
-
-
-
-
-
(Locked)
Learning objectives1m 55s
-
(Locked)
Learn about writing and running JavaScript programs1m 44s
-
(Locked)
Write a JavaScript program for the browser12m 4s
-
(Locked)
Move JavaScript to an external script1m 20s
-
(Locked)
Install Node.js and NPM1m 58s
-
(Locked)
Write a Node script5m 57s
-
(Locked)
Use Babel to transpile code3m 2s
-
(Locked)
-
-
-
-
-