JavaScript
JavaScript is a popular programming language supported by almost all modern browsers. JavaScript is used for adding functionality and interactivity to web pages. The script element is used for providing JavaScript code.
Script Element
The script element is similar to the style element. The difference is the script is used for adding JavaScript and the style element is used for adding CSS. The script element can be included in both the head section or the body section of the web page.
<script> document.write("Hello"); </script>
This method of writing the script inside the web page itself has some advantages. It does not require an additional file to be loaded. Another method of including JavaScript is to include it in an external file.
<script src="example.js"></script>
Using this method we can include the same JavaScript file in multiple web pages. There is no limit to the number of JavaScript files.
The script element is unique due to the fact that it can be placed inside both head and body sections. But the best place to have script elements is at the bottom of the web page. If the script elements are placed just before the ending body tag, then it leads to optimal page loading. The page renders smoothly and script files load later. If the script files are placed at the beginning the page may wait for the scripts to be loaded.
Noscript Element
The noscript element acts as a fallback for the script element when the browser does not support it. More often than not even if the browser supports the script element, some users may disable the JavaScript from loading. So notifying these users that JavaScript is required can lead to these users enabling JavaScript if they wish to see our content.
<noscript> JavaScript is not supported or turned off. Turn on JavaScript for more content. </noscript>