Comments are lines that are not evaluated when the code runs. They exist just for human readers, in other words. Comments can be extremely useful when we’re looking back at code we’ve written later on and for other people who will be looking at your code.
A single line comment will comment out a single line, and is denoted with two forward slashes
A multi-line comment will comment out multiple lines, and is denoted with
/*to begin the comment, and
*/to end the comment./* console.log('All of this code'); console.log('Is commented out'); console.log('And will not be executed); */
Let’s practice adding some code comments.
To the right, we’ve provided you with the beginning of the book Catch-22 by Joseph Heller.
On line 1, write a single line comment that says ‘Opening line’.
Single line comments are great for adding context to your code.
Multi-line comments are often best suited to prevent a block of code from running. Comment out lines 4 - 9 with a multi-line comment.