1. Single-line Comment
As its name implies, a single-line comment is a comment restricted to only a single line within the code. You can place a single-line comment either before or after a statement within the code.
// You can write a single-line comment here.
- Single-line comment added after a statement:
var a = 5; //Declaring variable a with initial value 5
- Single-line comment added before a statement:
var a = 5; var b = 5; // Adding variable a and b, and storing the value in another variable c var c = a + b; // Output the value of c in console console.log (c);
2. Multi-line Comment
Multi-line comments are different from single-line comments in the way that it allows you to add several comment lines in the code.
/*You can add
/*This is a script for adding two variables - x and y. We will store the result in another variable z. Also, the result is output in the console. */ var x = 5; var y = 5; var z = x + y; console.log (z);
Hi! I am Pankaj, a full-time content specialist and a part-time programmer and marketer. I love to explore new places and also new ideas. I am an inquisitive person with a passion to learn new skills through every possible opportunity that comes in the way.