Comments

JavaScript Comments are verbose text placed by the programmer in a script, to enhance the readability of the script.

Comments are ignored by the interpreter. Hence, it is only for the purpose of human reading, not for execution.

There are two kinds of comments in JavaScript, based on the number of lines a comment spans. They are

  • Single-line comments
  • Multiple-line comment

Single-line Comments

Single-line comment begins with double forward slash // and the comment (verbose) follows.

</>
Copy
//this is a single line comment
function printMsg() {
    alert("Hello World"); //this is also a single-line comment
}

Multiple-line Comments

Multiple-line comment begins with /* and ends with */, and the comment (verbose) is enclosed between these two.

</>
Copy
/*
This is a multi-line comment.
This is the second line of the comment.
*/
function printMsg() {
    /* This is 
       also a 
       multiple line comment. */
    alert("Hello World");
}

Conclusion

In this JavaScript Tutorial, we learned about comments, and types of comments in JavaScript, with examples.