-
-
Save mannyyang/f4057fda8f8591bb79299880e1b21345 to your computer and use it in GitHub Desktop.
JS Comment Categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| When developing, it's always a good idea to create comments so future you and other developers can better understand the logic that was thought of at that moment in time. Since comments can be used for different reasons and be formatted differently as well, I figured it would be a good idea to use specific formats for different types of comments. | |
| 1. Function Declarations | |
| The typical way of commenting function declarations with slash stars. | |
| Example: | |
| /** | |
| * Map array items to work with select options. | |
| * | |
| * @param {Array} arr Array of items that have properties id and name | |
| * @returns {Array} | |
| */ | |
| function test() {} | |
| 2. Inner Object/Function/etc. | |
| Standard slash slash comments for one liners or when you need to talk about the specific line below | |
| Example: | |
| const obj = { | |
| ... | |
| // Some comment about the property set below | |
| theKey: {}, | |
| ... | |
| }; | |
| 3. Headers | |
| Sometimes you'll have a situation such as a utility library where you have a list of functions and you want to better organize them in a way you can read them easier. I like to use comments to create separation between certain segments with the slash dash style. | |
| Example: | |
| //-- GENERAL --// | |
| ... | |
| export someFunction() {} | |
| ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment