Advantages of using Comments
Types of Comments
- Single Line Comments
- Single line comments start with //.
- Any text you type, between // and the end of the line will not be executed.
- Example :
- var x=20;
// x = 40;
- 20 will be displayed in the Console Tab because first we declared x and stored the value of 20 in it.
- then we have reassigned the value of x to 40. (but this line is commented and will not be executed).
- So, 20 will be displayed in the Console.
- Multi Line Comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be not be executed.
var x = 10;
var y = 20;
var z = 50;
x = y + z;
10 will be displayed in the Console Tab because first we declared x and stored the value of 10 in it.
then we have reassigned the value of x to y + z i.e. 50 + 20 (but this line is commented and will not be executed).
So, 10 will be displayed in the Console.
You can write anything inside comments, it will not be executed. As in first line I have written variable declaration in the commented line for reference that variable declaration starts from here.