JSDoc for a Simple Function
Generate JSDoc comments for a simple JavaScript or TypeScript function with parameters and a return type. Covers @param and @returns tags.
Detailed Explanation
Documenting a Simple Function with JSDoc
The most common use of JSDoc is documenting a plain function with parameters and a return value. A well-documented function tells other developers (and your future self) what it does, what it expects, and what it returns.
Example Signature
function calculateArea(width: number, height: number): number
Generated JSDoc
/**
* Calculates the area of a rectangle.
*
* @param {number} width - The width of the rectangle in pixels.
* @param {number} height - The height of the rectangle in pixels.
* @returns {number} The calculated area (width * height).
*/
Key Tags
| Tag | Purpose |
|---|---|
@param |
Documents a function parameter with its type and description |
@returns |
Describes the return value and its type |
Best Practices
- Start the description with a verb in third person ("Calculates", "Returns", "Validates")
- Include units or constraints in parameter descriptions when applicable
- Mention edge cases in the description (e.g., "Returns 0 if either dimension is negative")
- Keep the first line concise — use additional lines for details
JSDoc vs TSDoc
In JSDoc style, types are included in braces: @param {number} width. In TSDoc style, types are omitted because TypeScript already provides them: @param width. The generator handles both with a single toggle.
Use Case
Documenting utility functions in a shared library where other team members need to understand the API without reading the implementation. Common in math utilities, string helpers, and data transformation functions.