Description

JavaScript Comments are used to provide extra information related to the source code.

  • Comments are ignored and not processed.
  • Comments must be simple to read and understand.
  • They are helpful in understanding the source code, now and later, by the same or different programmer.

Comments can extend to one or more lines as explained below.

Single-Line Comments

Single line comments begin and end on the same line as shown below.

  • It begins with a double forward slash (//), followed by comment text.

Run this on IDE

// Single line comment in JavaScript
document.write("Hello World!");

Multiple-Line Comments

Multi-line comments begin and end on different lines, which can extend to multiple lines as shown below.

  • It begins with a single forward slash and an asterisk (/*), followed by comment text, and ends with an asterisk and a single forward slash (*/).

Run this on IDE

/* Multi-line comment
in JavaScript
extends to more than one line */
document.write("Hello World!");

Overall

Javascript comments help us in documenting extra information within the source code.

Related Links