How to Add Comments in Node.js
It's import for software developers to be able to leave comments in their source code. Comments help other contributors understand the code as well as highlight important sections.
Comments are exactly what they sound like. Comments are added to lines of code and/or throughout functionality in the codebase as annotations and are ignored by the interpreter when building. Since comments are ignored, they serve an informational purpose for the contributors of a project and have no effect on the code’s functionality.
Comments are commonly used to help described what a piece of code is doing so that other contributors working in the codebase can easily digest what they’re looking at. Comments are also used to designate the need for future work within a codebase, typically with the ‘TODO:’ placed before the comment itself.
There are multiple ways to comment a file, but for now let’s go through two ways to add comments to your Node.js code.
Single Line & Inline Comments
The easiest way to add a comment to your code is to prefix your comment with two back slashes (“//”). You can add the two slashes at the start of a line and type your comment as well as appending your comment to a specific line by adding the back slashes and comment inline with the thing you’re describing.
Single Line Comment
Block comments are typically used when the commentor needs to specify a lot of information in a single comment. Block comments are created by starting your comment with ‘/', typing your comment across multiple lines, and ending your comment with '/’. Block comments are also benficial when the commentor needs to specify a list of items such as TODOs.
Thanks for reading!