Being a programmer it is crucial that you keep track of code blocks and their various sections. Moreover, it’s a good practice to document the work.
Not only it helps you to understand. But also give a meaningful explanation to other developers, who might work on the same project.
- And Multi-line comment
If you add
Thus, anything after
// is ignored ( single line only).
By convention, a line starting with
// acts as a header. And it is often added at the end of a line to explain the line of code.
/* at the start and
*/ at the end. Anything in between /* and */ is treated as a comment and will be ignored by JS engines.
Multi-line comments are used mainly to comment out a block of code at one go. It is also used to document a paragraph by including a more detailed explanation.
Note: We have used multi-line comments in the above example to exclude the execution of a code block. See lines 12 to 14 as a reference.
Programmers also use comments to quickly debug and do temporary bug fixes. Allowing not to delete the existing line/block of code but to simply comment it out.
Certainly, comments play an important role.