JS-101-Fundamentals
  • JavaScript Library
  • 1-JavaScript Fundamentals
    • 0-Getting Started
      • Welcome
    • 1-JS-Fundamentals
      • 1-Grammar and Types
        • Comments
        • Declarations
        • Scope
        • Hoisting
        • Types
        • Literals
      • 2-Control Flow and Error Handling
        • if
        • if else
        • switch
        • try catch
        • throw
      • 3-Loops
        • For Loops
        • For In Loops
        • For Of Loops
        • Do While
        • While Loops
      • 4-Functions
        • Declarations
        • Expressions
        • Calling Functions
        • Scope
        • Parameters
        • Arguments
        • Closures
        • Closures Challenge
        • Arrow Functions
        • Predefined
      • 5-Expressions and Operators
        • Assignment
        • Comparison
        • Ternary
        • Typeof
        • Left Hand Side
        • Spread
      • 6 Numbers and Dates
        • Numbers
          • Numbers Enhanced
        • Math
        • Dates
      • 7 String Methods
        • String Literals
        • Methods
      • 8 Regular Expressions
        • Basic Intro
      • 9 Arrays
        • Array Review
        • Populating/Referring
        • Length
        • Iterating
        • Methods
      • 10 Objects
        • About Objects
        • Properties
        • Enumeration
        • Initializers
        • Constructor Functions
        • this
        • create
        • Methods
      • 11 ES6 Intro
        • ES6 Intro
        • let
        • const
Powered by GitBook
On this page
  • Purpose of Comments
  • Single Line Comments
  • Multiple Line Comments
  • File Location
  • Practice
  1. 1-JavaScript Fundamentals
  2. 1-JS-Fundamentals
  3. 1-Grammar and Types

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.

Previous1-Grammar and TypesNextDeclarations

Last updated 7 years ago