Adding JavaScript to a Web page
Just like CSS stylesheets are added to an HTML page, JavaScript files can be externally linked in a similar way using the <script>
tag within the head or body element.
SNIPPET
1<!DOCTYPE html>
2<html>
3<head>
4<title> My First Webpage </title>
5<link rel="stylesheet" href="style.css">
6<script src="script.js"></script>
7</head>
8<body>
9<h1> Hello World! </h1>
10</body>
11</html>
Scripts can also be embedded within the HTML document by writing the JS code within the <script>
tag. However, the recommended approach is to use external scripts as this approach allows us to reuse the same script for multiple HTML files.