Sample script with comments
This first example has a JavaScript that does nothing.
Select from the Menu "View - Source" (or "View - Page Source" in Netscape) to see the source code for this page.
- The script on this page is placed between the <head> and </head> tags,
but not inside the <title> and </title> tags
- Everything between the <script> and the </script> tags is the Javascript
- Within the script tag, define the language to be used: language="JavaScript"
- The initial <!-- and the final //--> are used to hide the JavaScript from
version 1 or 2 Browsers that did not know the <script> tag.
These lines are optional, but must both appear, or neither appear in the script.
- The JavaScript on this page currently contains only 2 Comments
- // placed anywhere on a line causes the rest of the line to be ignored.
This type of comment allows a short comment to be placed either on its own line, or to the right of some code.
- for multi-line comments, a /* combination will cause everything to be ignored by JavaScript
until a */ combination is found.
- Notice that just as within HTML, spacing and tabs are ignored within JavaScript
(with the possibility of a few exceptions - such as the // comment ending at the end of the line)
Go to the next script |
Go to the JavaScript Index