As we write JavaScript, we can create comments in our code.

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.

There are two types of code comments in JavaScript:

  1. A single line comment will comment out a single line, and is denoted with two forward slashes // preceding a line of JavaScript code.

    // The first 5 decimals of pi console.log('Pi is equal to ' + 3.14159);
  2. 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.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Already have an account?