<script> and closing
</script> tags. And an HTML file can have more than 1 <script> tags.
As the browser parse the HTML document from top to bottom, that’s why the
<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.
<script> tag and
Placement of the Script Tag:
<script> in the <head> tag
<script> in the <body> 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://firstname.lastname@example.org/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"> </script>
defer attribute 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.
defer attribute only works with external Script.
<script src="js-external.js" defer> </script>
integrity attribute contains the
filehash value which allows the browser to check the fetched script.
<script src="https://email@example.com/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
The 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>
reffererpolicy attribute 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.
By case-sensitive programming language, we mean we can not use different case staying to access the same object, for example
alert() will prompt up an alert box but
ALERT() will throw an error.
Comments are used to provide extra information about the code itself, the browser interpreter does not execute the comment.
- Single Line Comment
- Multi-Line Comment
To write a single line comment we use the double backslash symbol //
<script> //this is a single line comment </script>
/*symbol and ends with
<script> /* This is a multi line comment */ </script>
People are also reading: