HTML Fundamentals

  1. The <script> HTML element is used to embed executable code
  2. This is typically JavaScript

Notes

defer: This boolean attribute indicates to browser that the script is meant to be executed after the document has been parsed, but before firing DOMContentLoaded.

The script tag should either be included
  1. Between the <head> tags
  2. Just before the closing <body> tag

JavaScript is often placed before the closing body tag to help reduce the page loading time. Doing this allows the rest of the page to load before loading the JavaScript files, which can be large

Example

<script src="javascript.js"></script>
<script type="text/javascript" src="javascript.js"></script>
<script>
  alert("Hello World!");
</script>

Mnemonic

(scr)ipt is src

References