JSDoc

4.0.5 · active · verified Sun Apr 19

JSDoc is an API documentation generator for JavaScript, enabling developers to create static HTML documentation websites directly from specially formatted comments within their source code. It supports modern JavaScript features, including ES2015 classes and modules, through its use of the Babylon (now @babel/parser) JavaScript parser. The project is actively maintained, with the current stable version being 4.0.5, and receives irregular but consistent updates focused on bug fixes, Node.js compatibility, and parser improvements. Key differentiators include its long-standing presence in the JavaScript ecosystem (since 1999), flexible configuration options via JSON or JavaScript files, and a rich community ecosystem offering numerous custom templates and build tool integrations (e.g., Grunt, Gulp). JSDoc allows for comprehensive annotation of functions, classes, modules, and parameters, facilitating improved code readability, maintainability, and providing rich IntelliSense support in modern IDEs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install JSDoc locally, add JSDoc comments to a JavaScript class, and generate HTML documentation into a './docs' directory using an npm script.

npm install --save-dev jsdoc

// my-module.js
/**
 * Represents a simple calculator.
 * @class
 */
class Calculator {
  /**
   * Adds two numbers.
   * @param {number} a - The first number.
   * @param {number} b - The second number.
   * @returns {number} The sum of a and b.
   */
  add(a, b) {
    return a + b;
  }

  /**
   * Subtracts two numbers.
   * @param {number} x - The number to subtract from.
   * @param {number} y - The number to subtract.
   * @returns {number} The difference of x and y.
   */
  subtract(x, y) {
    return x - y;
  }
}

module.exports = Calculator;

// package.json (add this script)
// {
//   "scripts": {
//     "generate-docs": "jsdoc my-module.js -d ./docs"
//   }
// }

// To run: npm run generate-docs

view raw JSON →