JSDoc Documentation
Jsdoc
π¨βπΌ Code without documentation is like a recipe without instructionsβtechnically
all the ingredients are there, but good luck figuring out how to use them!
JSDoc is a documentation format that lives in special comments above your
functions. The best part? TypeScript and your IDE understand JSDoc, so your
documentation shows up in tooltips and autocomplete.
/**
* Calculates the area of a rectangle.
* @param width - The width of the rectangle
* @param height - The height of the rectangle
* @returns The area in square units
* @example
* const area = calculateArea(5, 10)
* console.log(area) // 50
*/
function calculateArea(width: number, height: number): number {
return width * height
}
When you hover over
calculateArea anywhere in your codebase, you'll see this
documentation!Since TypeScript already provides type information (parameter types, return
types), JSDoc is primarily useful for descriptions and examples in
TypeScript projects. The
@param and @returns tags add human-readable
explanations that go beyond what types alone can convey.Common JSDoc Tags
| Tag | Purpose |
|---|---|
@param | Documents a function parameter |
@returns | Documents what the function returns |
@example | Shows how to use the function |
@throws | Documents errors the function throws |
@see | Links to related documentation |
π¨ Open
and add JSDoc comments to each function.
Some functions in this exercise use built-in Math methods: -
Math.pow(base, exponent) - raises base to the power of exponent (e.g., Math.pow(2, 3)
returns 8) - Math.max(a, b) - returns the larger of two numbers -
Math.min(a, b) - returns the smaller of two numbersπ° Put a brief description immediately after the opening
/**.π JSDoc Reference