JavaScript code can be added directly to the HTML document by enclosing the code in a SCRIPT element (ex. 1) or by linking a JavaScript file to the document by using the SRC attribute in the opening SCRIPT tag (ex. 2).
Example 1
<script>
/* This is My Javascript */
</script>
Example 2
<script src="my-external-javascript.js"></script>