Multi-line Comments

Multi-line comments start with /* and end with */. Any text between /* and */ will be ignored by JavaScript. This example uses a multi-line comment (a comment block) to explain the code:

HTML file: Displayed by browser:
<body>
<h1 id="myH"></h1>
<p id="myP"></p>
<script>
/*
The code below will change
the heading with id = "myH"
and the paragraph with id = "myp"
in my web page:
*/

   document.getElementById("myH").innerHTML = "My First Page";
   document.getElementById("myP").innerHTML = "My first paragraph.";
</script>
<p><strong>Note:</strong> The comment block is not executed.</p>
</body>

Note: The comment block is not executed.

It is most common to use single line comments. Block comments are often used for formal documentation.

BackTable of ContentsNext