Comments
JavaScript comments can be used to make the code more readable. They do not get executed by the browser and perform no action.
There are two types of JavaScript comments, single line and multi-line.
Single Line Comments
JavaScript single line comments start with two forward slash characters (//).
The single line comment has the form:
// comment text
Note: There is no need to "close" a single line comment since it ends automatically at the next line.
The following example shows some JavaScript code with some single line comments:
<script>
// Write the heading
document.write("<h1>Heading Text</h1>");
// Write the paragraph
document.write("<p>Paragraph Text</p>");
</script>
Multi-line Comments
Multi-line comments start with /* and end with */. These comments can span multiple lines and must be closed.
The multi-line comment has the form:
/* comment text */
The following example shows the same JavaScript code as above, but with a multi-line comment:
<script>
/*
Write the heading
and the paragraph
*/
document.write("<h1>Heading Text</h1>");
document.write("<p>Paragraph Text</p>");
</script>