To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Part 2.2Comments in JavaScript

Very few programming languages do not support comments. Comments are useful ways of adding contextual information about a piece of code in a program.

JavaScript comments

JavaScript features comments too. In JavaScript a comment is signified by either of the following two symbols:

  • //
  • /* */

The difference between these two types of comments is that the first version only works across a single line:

//This is a comment

The second version can span multiple lines:

/* This is a comment
 * This is also a comment

It is often the case to use an asterisk on each line between the opening and closing comment tags as shown on line 2 previously but it is not completely necessary.

Code previewClose
Feedback 👍
Comments are sent via email to me.