JavaScript file ends with a .js
. These files are then stored in a js Folder that's located at the same level of your HTML for easy indication.
attached folder structure below [for clear visualization]
Like this
Now let's get into main topic for our discussion.
** Linking your JavaScript file to your HTML file**
For JavaScript files to work , we need to link them you HTML file - > This can be done by adding script tag at the bottom of the html document before closing the body tag or inside inside head section
<html>
<head>
<meta charset="utf-8" />
<title>Title website </title>
</head>
<body>
<!-- Please enter js script inside -->
<script src="js/index.js"></script>
</body>
</html>
In index.js file ,Let's enter alert('Javascript file linked')
.
If we try to open the index.html , the browser will display a pop that says "Javascirpt file linked".
Happy learningđź’—