Adding JavaScript
To add JavaScript to a web page, there are two main approaches:
- Using a
script
tag in thehead
element: In this version, you would add a script tag to an existing HTML page, for example, namedindex.html
.<!-- Alt1 --> <script> // JavaScript here </script>
- Pointing to a stand-alone file: In this case, you would write your JavaScript in an existing file,
my-javascript-file.js
:<!-- Alt2 --> <script src="my-javascript-file.js"></script>
The role of JavaScript
When JavaScript was first added to the browser, it played the role of adding interactivity. Today, JavaScript often has an extended role as part of application frameworks like Vue.js, React, and Angular. In such frameworks, a developer can now declaratively define templates that, with the help of JavaScript, can be turned into static HTML, with event handling added, to respond to user interactions. Ultimately...