Chapter 2: The Javascript Console

2.2 Comments

CommentsNow that we are familiar with the Javascript console, let's discuss two more concepts that we’ll be needing in the next few chapters – comments and escape sequences.

Comments are notes that we add to our code to make them more readable for other programmers. They are meant for humans to read and are ignored by the computer.

To add a single line comment to our program, we add a // sign in front of each line of comment.

Example:

//This is a comment

To add multi-line comment, we use /*…*/.

Example

/* This is a multi-line comment
Comments are ignored by browser
End of multi-line comment */

Try adding the following lines to chap2.js:

//console.log("Hello World Again");

/*This is a multi-line comment
console.log("Hello World for the third time");
End of multi-line comment*/

You’ll see that the lines are grey in color. If you run the code, the messages “Hello World Again” and "Hello World for the third time" are not displayed because these lines are comments and are ignored by the computer.