1.

JavaScript Fundamentals

Answer»

  • Writing JavaScript code in an HTML page: We must enclose the JavaScript code within the <script> tag in order to include it on an HTML page just as the example shown below:
<script type = "text/javascript">
//JavaScript coding can be done inside this tag
</script>

With this information, the browser can correctly make out that the code is written in JavaScript and execute the code.


  • Inclusion of external JavaScript files in an HTML file: An external JavaScript file can also be written separately and included within our HTML file. That way, different types of code can be kept isolated from one another, resulting in better-organised files. For instance, if our JavaScript code is written in the file script.js, we can include it in our HTML file in the following way:
<script src="script.js"></script>

  • Usage of Comments in JavaScript coding: Comments are extremely useful in programming because they can assist others to understand what's going on in your code or they can help you if you have forgotten something. Keep in mind that they must be correctly identified so that the browser does not attempt to execute them. There are two alternatives available in JavaScript in which we can add comments:


    • Single-line comments: If you want to include a single line comment, start it with "//".


    • Multi-line comments: If you want to write a comment that spans multiple lines, you can wrap it in /* and */ to prevent it from being executed.





Discussion

No Comment Found