External JavaScript Code

External JavaScript Code
Rating: 3 - 2 Votes

External JavaScript Code

JavaScriptExternal JavaScript code is placed inside an external JavaScript file.  This external JavaScript file contains a lengthy JavaScript code.  If you place same lengthy code inside a HTML file, it will make your whole code file look ugly.  It’s a good habit to place all lengthy code inside an external JavaScript file and add path of it in the HTML file using src attribute of the script tag.  Sample code is given below.  In this scenario, both HTML and JavaScript files are located in the same folder.

HTML File

JavaScript File