From the course: JavaScript Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

JavaScript as an external file

JavaScript as an external file - JavaScript Tutorial

From the course: JavaScript Essential Training

Start my 1-month free trial

JavaScript as an external file

- [Instructor] Writing JavaScript in line in an HTML document like this is a bit of an edge case, and it only really makes sense when you have just a little bit of JavaScript, and it only applies to the current document and nowhere else. In most cases, when you write JavaScript, you'll have a lot of script and you want to apply it to several different documents. In those circumstances, the best practice is to take the script, place it in its own file or several different files, and then just reference the files whenever you want to use them. There's already a model for this in how we handle CSS. If you have just a few lines of CSS and you want to apply it to just one document, it's fine to place it inside the document using the style tag, but in most cases, you want to place your styles in a separate style sheet and then call the style sheet in when you want to use it. We're going to do the exact same thing with scripts…

Contents