This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

JSDoc 3 Documentation Cheatsheet

A comprehensive reference guide for JSDoc 3 annotations: @param, @returns, @typedef, @type, @template generics, @async, and TypeScript type checking.

· Published

JSDoc is an API documentation generator and type-annotation format for JavaScript, supported by TypeScript language servers.

Function Annotations

/**
 * Calculates total invoice sum including tax.
 *
 * @param {number} subtotal - Net amount before tax.
 * @param {number} [taxRate=0.1] - Optional tax percentage (defaults to 10%).
 * @param {string} [currency='USD'] - Three-letter ISO currency code.
 * @returns {number} The calculated total invoice price.
 * @throws {RangeError} When subtotal is negative.
 */
function calculateTotal(subtotal, taxRate = 0.1, currency = 'USD') {
  if (subtotal < 0) throw new RangeError('Subtotal must be positive');
  return subtotal * (1 + taxRate);
}

Type Declarations & Aliases (@typedef)

/**
 * @typedef {Object} UserProfile
 * @property {number} id - Unique numeric identifier.
 * @property {string} username - User account handle.
 * @property {string} [email] - Optional contact email address.
 * @property {'admin' | 'editor' | 'member'} role - Access control role.
 */

/**
 * Loads user record from database.
 * @param {number} id
 * @returns {Promise<UserProfile>}
 */
async function getUser(id) {
  // ...
}

Common JSDoc Tags

Tag Description Example
@type {Type} Declares the type of a variable /** @type {string[]} */
@param {Type} name Documents a function parameter /** @param {HTMLElement} el */
@returns {Type} Documents the return value /** @returns {Promise<void>} */
@async Indicates function is asynchronous /** @async */
@deprecated Marks symbol as obsolete /** @deprecated Use fetchUser() instead */
@see Link to external documentation /** @see {@link https://example.com} */
@template T Declares generic type parameter /** @template T @param {T} item */

References

Related topics