SCRIPT tags that come in the form of:
<script> … </script>
You need to do this because the SCRIPT tags alert the browser program to start interpreting all the text between these tags as a script.
With this function, you can write out plain text or even HTML. This is the basic syntax.
<script> document.write("Hello World!") </script>
- Portability: Externally linked scripts allow you to use that code on multiple web pages. It also allows you to maintain the source code independently of your HTML
- Performance: externally linked scripts especially those loaded from another domain or server like a CDN (content delivery network) help reduce the number of HTTP requests. It also allows these filed to be cached locally by the web browser
Hello World From Script! Hello World From Embedded!
This is the contents of the HTML file:
This is the contents of script.js
The above script finds an element within the HTML file with an id of “elem” and changes the contents to Hello World From Script!
The embedded script then finds the same element within the HTML file with an id of “elem” and appends Hello World From Embedded! to the content.