Comments

Purpose of Comments

Comments allow us to do the following:

  1. Communicate with other developers by writing notes in plain English.

  2. Annotate certain aspects of our code for our future selves.

  3. Add TODOs in our code.

There are two ways to do comments in JS.

  1. Single Line Comments

  2. Multiple line comments

Single Line Comments

Two slashes // will allow you to do a single line comment. See the example below:

// This is one line commented out
console.log("This is underneath the comment and will run.");

Multiple Line Comments

A /**/ will allow you to do multi-line comments. Anything inside the asterisks will be commented out and will not execute.

/*
    multiple lines commented
    out in a block
    Remember that commented code will not run.
    None of this code will run.
*/

console.log("Howdy");

File Location

    javascript-library
        └── 0-PreWork
        └── 1-Fundamentals
            └── 1-Grammar-and-Types
                01-comments.js <-- You are here

Practice

  1. In comments.js go ahead and create a variable called myAge.

  2. Add a single line above the variable.

  3. Print the variable to the console.

  4. Above the print statement, add a simple multi-line comment.

Last updated