Checkout this video:
The ‘Script’ Element
If the script element is placed in the head section, it is executed when the page is loaded. If it is placed in the body section, it is executed when the statement is reached.
The script element has two attributes which are mandatory for older versions of HTML:
src: This attribute specifies the URL of an external script file. If this attribute is present, it must have a value that contains a URI.
The ‘noscript’ Element
If a browser does not support script, or if the user has disabled scripting, it will display the content inside the ‘noscript’ element. Script-supporting browsers ignore the ‘noscript’ element.
The ‘noscript’ element should only contain information that is useful to users who don’t have access to script, or who have disabled script in their browser. Do not put misleading information in the ‘noscript’ element.
When to Use an External Script
-Your HTML file will be smaller and easier to read.
-You can link to the same external script on multiple HTML pages, which means you don’t have to duplicate your code.
Of course, there are also some drawbacks to using an external script:
-It requires an extra HTTP request, which can slow down the loading of your page.
-It can be more difficult to debug if something goes wrong.
When to Use an Inline Script
Sometimes it just makes sense to write a quick little script and throw it right into your HTML. When the script is short and not likely to be reused, or when you’re experimenting, inline scripts can be very useful. To insert an inline script, just put the code right inside any “` tag. As long as you call document.write() before the browser reaches the tag, you can add HTML anywhere on the page.