<script>tag will execute before the
<body>tag. When you execute the above HTML file in your web-browser you will see a similar output.
Placement of the Script Tag:
<script> in the <head> tag
Script Element Attributes
The <script> Element supports 8 attributes
- async (only for External Script)
- defer (only for External Script)
<script src="js-external.js" async> </script>
<script src="https://email@example.com/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"> </script>
deferattribute is the opposite of
asyncattribute, it is also a boolean attribute but it does not execute or run the page until the complete HTML page gets parsed by the browser.
deferattribute only works with external Script.
<script src="js-external.js" defer> </script>
attribute contains the
value which allows the browser to check the fetched script.
<script src="https://firstname.lastname@example.org/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
nomoduleThe nomodule is a boolean attribute that represents whether or not to execute the Script in the browser that supports ES2015 modules.
<script nomodule> alert("Hello")</script>
reffererpolicyattribute represent which referrer information to send when the script is fetched.
<script src="js-external.js" referrerpolicy="origin"> </script>
<script src="js-external.js" > </script>
The type attribute defines the media type of the script.
will prompt up an alert box but
will throw an error.
- Single Line Comment
- Multi-Line Comment
To write a single line comment we use the double backslash symbol // Example
<script> //this is a single line comment </script>
/*symbol and ends with
<script> /* This is a multi line comment */ </script>
People are also reading: