Comment Your JavaScript
By far, the most common use for JavaScript comments is to hide JavaScript functions from older browsers that don't support JavaScript. However, as we noted in a June 2002 JavaScript Tip, new browsers may ignore your JavaScript because of those tags!
A better use of comment tags is to describe the purpose of a function, detail the variables, etc. JavaScript comment syntax is quite similar to HTML comment syntax. Like CSS comments, JavaScript comments must be placed inside the opening and closing SCRIPT tags:
<script type="text/javascript" language="javascript"> <!-- Countdown function: days until the class reunion // --> JavaScript function here </script> |
Note the final two forward slashes. They're important! They keep the closing hyphens and bracket (-->) from being processed as part of the script. Be sure to always include them at the end of your JavaScript comment text.