External JavaScript file

The software developer can easily create an external JavaScript file and this script can be embedded into the html page.

This external file provides the facility of code re-usability because the single JavaScript file can be easily used in various html pages. Whenever you are making an external JavaScript then make sure that the file is saved in .js extension.

The experts have recommended embedding all the JavaScript files into one single file. When all the files are embedded in one file the speed of the web page increases.

Example


alert.js


function msg(){
 alert("Hi javascript tutorial for beginners");
}
 

index.html

<html>
<head>
<script type="text/javascript" src="js/alert.js"></script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>

Javascript Interview Questions and Answers
  • What is the full meaning of SRC?
  • What is a javascript file?


Next ConceptJavaScript Comment