Comments in JS

Comments is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand. comments are not displayed in the browser. Comments in JS

It’s a good idea to put a comment in front of a method or function to describe what it does (with what) and what it returns, and in front of a class telling what it’s for. And so on.

There are two types of comments in JavaScript.

  1. Single-line Comment
  2. Multi-line Comment

Single-line Comments in JavaScript: Comments in JS

Single-line comments in JavaScript start with //

let x = 10;      // Declare x, give it the value of 10
let y =  20;  // Declare y, give it the value of 20
let a = 5;      // Declare a, give it the value of 5
let b = a + 10;  // Declare b, give it the value of a + 10

Multi-line Comments in JavaScript:

Multi-line comments start with /* and end with */

/*
The code below it print
the loop upto 99
*/
console.log("Entering for loop");
for (let i = 0; i < 100; i++) {
    console.log(i);
}
/*
console.log("Entering for loop");
for (let i = 0; i < 100; i++) {
    console.log(i);
}
*/
  1. Comments is a programmer-readable explanation or annotation in the source code of a computer program.
  2. Single-line comments in JavaScript start with //
  3. Multi-line comments start with /* and end with */ Comments in JS