There are two ways we can include javascript code in the HTML
- Embedded Js: In this, we add the script tag directly in the HTML document as shown below:
<script> document. Write (“Welcome!”)</script>
Can add the script tag either in the head section of the body section of an HTML document depending on when you want the script to be loaded
- External Js: create a separate javascript file and save it with .js extension and with the help of src attribute of script tag add the .js file to the HTML document as shown below:
<script src=”file1.js”></script>