JavaScript Tutorial - Comments Galore

Left
Right

If you intend to write programs then the first thing to learn is that
_BLINK(_BOLD(commenting your code is a requirement)).

There are several ways to comment HTML/JavaScript code.

Comments:

  • Header info for any defined functions
  • Explain details that are not apparent
  • Document algorithms for easier maintenance 6 months or much later.
  • Good code has roughly 10% (or more) of the lines as comments

The code below demonstrates how to comment HTML, and a couple of ways to document JavaScript. Note, that they are different and can not be used interchangeably.

An example: work/comments.html

<HTML>
<BODY>
<H1> Severely commented code </H1>
<!-- these are HTML comments -->
<SCRIPT LANGUAGE="JavaScript">
// C++ style of comments (only to end of line)
document.write("<H1>Hello World!</H1>");
/* C style of comments,can be multi-lined
 * and goes until
 * the following token is given ->  */
</SCRIPT>
<P>
Notice that the JavaScript code is embedded in the HTML mark-up
for a web page.
<P>
<SCRIPT LANGUAGE="JavaScript">
// a second block of JavaScript
document.write("<H2>Hi JavaScript!</H2>");
</SCRIPT>
</BODY>
</HTML>
Left
Right
Slide 3