JavaScript Comments


Single Line Comments

Short comments on one line begin with //.

Any text between the // and the end of the line won't be used by JavaScript (won't be done).

In this example, a brief note is placed before each line of code, all on a single line.

In this illustration, we employ a brief comment placed at the end of every line to clarify the code.


Multi-line Comments

Multi-line comments in HTML begin with /* and end with */.

JavaScript will not pay attention to any text enclosed between /* and */.

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


Using Comments to Prevent Execution

Comments are helpful for stopping code from running, especially when you're testing it.

When you put // before a line of code, it turns that line into a comment instead of an active piece of code.

This example uses // to prevent execution of one of the code lines:

This example uses a comment block to prevent execution of multiple lines: