What are Comments?
Different types of comments:
Since by now we have got to know the magical usages of a comment code, let us now dive into its types:
There are two types of comments:
- Single line comment
- Multi-line comment
Single line comment:
// everything written after double slash becomes a comment
Codes written within multi-line comments usually begins with /* and ends with */. Within this, we can add multiple lines of statements or documentation can be added within the comment section. This /*….*/ again prevents the interpreting whatever is written within it. Mostly, the multi-line comment is used in creating documentation.
/* This is a comment */
/* This is a multi-line Comment. It wont be displayed in the output. */
/* multiple lines can be added in multi line comments. One can even comment to run alternate code*/ console.log("Learning About Comments");
Usage of comments in coding:
- It can be used to run alternate code or block any code that is of no use.
- It is used to provide additional information associated to the coding.
- Multiple tricks or debugging solutions can be easily explained in comments while keeping the actual code intact.
- If a particular section of code is not necessary or got updated, but you still want to keep it for future reference without executing, comment is the ultimate solution.
- It can also be used for long-description and documenting new models or codes.
- Comments help fellow developers come under one page.
Practicing commenting in codes can really benefit, especially when we are in the enterprise development sectors. Developing application in the companies require team effort. There, you cannot and will not work alone. Thus, commenting specific sections of the code can help other team members understand and collaborate with efficiency and flexibility.