Monday, May 8, 2017

Comments

What are Comments?
Comment is a note to yourself  or other programmers about the code. Comments are not interpreted by JavaScript Engine. It is a good programming practice to do comments.

Why do we use Comments?
  • If we come back to our program after long time, there can be a chance to forget what we have done. So at that time, comments will help us to remember what we have done.
  • When writing code we may have some complex logic that is confusing, it will be better to put a comment in here explaining what is this logic is. So, in future It will not be confused us.
  • The programmers who watch our programs can understand the program.

There are two type of comments.

Single line comment
Only comment the line which write after //. This type of comment can be used for commenting out single lines of code and writing small notes. As an example, I use previous examples with comments.


And the result is,


As you can see, in here, the statements which are written with comment, doesn't display in web page.


Multi line comment
Can comment multi lines which are placed between /* and */ . These types of comments can be used to disable long segments of code or insert long-winded comments.

 Result is same as single line comment. 

Hope you'll use comments in your programs as a good practice.




No comments:

Post a Comment