JavaScript uses only one HTML element tag, which is <script>
. That means if you want to
write javascript code, then it has to be written within <script>
tag.
Internal JavaScript
We can add JavaScript code within <head>
and <body>
tag.
External JavaScript
We can add JavaScript code in an external file, and then import the file in our html code.
Note : Make sure that for external files with JavaScript code, should have .js
filename
extension, as that's how it
is
recognized as JavaScript.
Example : filename.js
Its a good practice to use external javascript files in terms of organizing your code and making it reusable across multiple HTML files. Plus, the HTML is easier to read without huge chunks of script dumped in it.