Programmers use comments within their code for several reasons:
To tell their future selves, and anyone else who works on the program in the future, why they wrote something in the particular way they did
To describe how the code they wrote works
To leave themselves a note telling what they still need to do, or to list improvements that they intend to make at a later date
Single‐line comments: Single‐line comments cause everything following them on the same line to be a comment. To create a single‐line comment, use two slashes (//) back to back. For example, here the first three lines are single‐line comments, and the fourth line contains a statement that will be executed, followed by a comment.
// The following code won't run. // alert("Watch out!"); // The next statement will run. alert("Have a nice day!"); // pops up a nice message
Multi‐line comments: Multi‐line comments are comments that can be more than one line long. To create a multi‐line comment, start with /* and end the comment with the exact reverse, */. Here is an example of a multi‐line comment.