We use the
In the following example we have created a single line comment.
//this is a single line comment console.log("Hello World!"); //this will console log "Hello World!" text
We use the
/* to start and
In the following example we have created a multi line comment.
//this is a single line comment /** * in the following code we are going to * console log "Hello World!" text */ console.log("Hello World!");
We use comments in our code to write some notes or prevent a piece of code from executing.
In the following example we are using both single and multi line comment to create note in our code so that anyone reading the code can understand its purpose.
//create two variables a and b var a, b; //setting value of a and b a = 10; b = 20; /** * computing the sum of the two variables * and using console log to display the result */ console.log(a+b); //this will print 30
In the following example we are using both single and multi line comment to prevent some piece of code from executing.
console.log(1); //print 1 console.log(2); //print 2 //following line will note execute as it is commented out using single line comment //console.log(3); //following code commented out as well using multi line comment /* console.log(4); console.log(5); console.log(6); */ console.log(7); //print 7