Documentation Comments in JSDoc
In JSDoc we need to include documentation comments in the code through which JSDoc will generate an HTML documentation website. Let’s see how to create documentation comments for different types of code.
String, Numbers & Arrays:
Here we have generated simple JSDoc comments with the description of variables and their data type which is denoted with the help of the @type tag.
In the above comment, we have specified the type of all properties of an object.
Here, the @param tag is used for documenting the different parameters of the function, whereas the @returns tag documents the return value of the function
- Before the declaration of the class, we have JSDoc comment to describe the class
- For Constructor, JSDoc comment similar to Function is used
- Inside the Constructor, to document variables, the @property tag is used
Linking instance of the class to its class
As we have created a class named “Owner”, so let’s create an instance of that class and link it to the class with the help of the @link tag
Final index.js file:
Output: Run the following jsdoc command:
npm run jsdoc
After executing the command, In the jsdoc folder, an index.html page would be created, open it in the browser to view the documentation site generated by jsdoc.
Documentation site Output:
Some common tags used in JSDoc comments:
- @author – To document the author of the code.
- @constant – To document constants.
- @default – Allows documenting the default value given to something.
- @function – This tag is used to describe the function or method.
- @global – Documents the global object.
- @implements – To document the implementation of an interface.
- @member – Documents the members of the function.
- @param – This tag is used to document parameters/arguments of the function.
- @returns – It is used to document the return value of the function.
- @type – To document the type of variables
Please Login to comment...