- Head Section
- Body Section
The Script tag
<script> ... </script>
- The <script> tag in the HTML page: An attribute src is used within the script tag where you need to pass the path of your External Script(.JS file).
<script src = "Filename.JS"></script>
If the file is saved in the same folder as the HTML file, the name of the file can be passed to the attribute src. Otherwise, you need to pass the complete path of the .JS file.
External file: index.js
Out of head section & body section, it is better to choose body section to insert the script.
Why not head section?
The browser examines the code from top to bottom. If the browser gets stuck with the script present in the head section, then other requested elements of the webpage may be ignored.
Why body section?
<script> document.write("Hello World!"); </script>
- document.write(): Due to the presence of Parentheses, we can say that this is a function which is used to display the output on the webpage. Parameters can be passed to the function within these parentheses.
- "Hello World": A sequence of characters placed inside a pair of single or double quotes is known as a String. Since the string is placed inside the parentheses of the function, it as a parameter to it.
Single-line Comment: (Double slash //)
Multi-line Comment: (/* ... */)
With the help of comments, you can create a detailed self-explanatory program. Along with this, you can selectively execute the statements, by commenting a line, to test the code for errors.