Comments
Purpose of Comments
Comments allow us to do the following:
Communicate with other developers by writing notes in plain English.
Annotate certain aspects of our code for our future selves.
Add TODOs in our code.
There are two ways to do comments in JS.
Single Line Comments
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
In
comments.js
go ahead and create a variable called myAge.Add a single line above the variable.
Print the variable to the console.
Above the print statement, add a simple multi-line comment.
Last updated