How to include JavaScript File in HTML5 ?
Link the External Script in HTML
To link an external script in HTML, use the <script>
tag with the src
attribute pointing to the external JavaScript file.
Syntax
<body>
<h1>My Web Page</h1>
<!-- External JavaScript -->
<script src="script.js"></script>
</body>
Link the Internal Script in HTML
To include an internal (inline) script directly within the HTML document, use the <script>
tag without the src
attribute
Syntax
<script>
// Your JavaScript code goes here
console.log("Hello, World!");
</script>