Comments in Node.js
Learn how to write clean, readable, and professional Node.js code using single-line, multi-line, and documentation (JSDoc) comments.
Single-line Comments
Single-line comments start with `//` and are best for short explanations, reminders, or clarifying what a specific line does.
1. Basic Single-line Comment
Everything after `//` on that line is ignored by JavaScript.
2. Inline Comment (End of Line)
Inline comments are placed at the end of a line to explain the line quickly.
3. Debug Notes / TODOs
Common practice: using keywords TODO, FIXME, NOTE so they can be searched easily in VS Code.
Multi-line Comments
Multi-line comments start with `/*` and end with `*/`. They are useful when you want to explain a block of logic or temporarily disable a block of code.
1. Basic Multi-line Comment
Multi-line comments can span across many lines and are great for explaining bigger blocks.
2. Temporarily Disable a Code Block
Useful during debugging when you want to stop some code from running without deleting it.
3. Warning / Big Notes
Many teams use multi-line comments for warnings or important notes.
Documentation Comments (JSDoc)
Documentation comments use `/** ... */` (notice the double asterisk). This style is called JSDoc and is widely used in Node.js projects. It helps IDEs (like VS Code) show function docs on hover and improves code maintainability.
1. Documenting a Function
Use `@param` to describe parameters and `@returns` to describe return values.
2. Documenting an Async Function
When a function returns a Promise, document it using `Promise<type>`.
3. Useful JSDoc Tags
These tags make your codebase self-documented and easier to maintain.