Course contentsShow
← JavaScript
Lesson 2611 of 2,72353. Type Safety Without TypeScriptFree lesson

Documenting Function Parameters with @param

Use @param to specify parameter names and types, improving function documentation and editor hints.

Documenting Function Parameters with @param

You'll learn how to use JSDoc's @param tag to document function parameters, giving yourself and your team better hints in modern editors.

The Core Idea

The @param tag lets you describe each parameter a function accepts: its name, its expected type, and what it represents. This creates inline documentation that IDEs read to provide autocomplete suggestions, type warnings, and helpful tooltips as you code.

Think of @param like labeling the inputs on a machine. Instead of guessing what each dial does, you get a clear label: "Temperature (number) - Set between 0-100°F." Your editor becomes smarter about what you're passing in.

Basic Syntax

/**
 * Calculates the area of a rectangle.
 * @param {number} width - The width of the rectangle
 * @param {number} height - The height of the rectangle
 * @returns {number} The calculated area
 */
function calculateArea(width, height) {
  return width * height;
}

The format is: @param {type} parameterName - Description

Multiple Parameters and Optional Values

/**
 * Greets a user with an optional title.
 * @param {string} name - The user's name
 * @param {string} [title] - Optional title (e.g., "Dr.", "Ms.")
 * @returns {string} The greeting message
 */
function greet(name, title) {
  return title ? `Hello, ${title} ${name}` : `Hello, ${name}`;
}

Square brackets [title] indicate an optional parameter.

Why This Matters

When you hover over calculateArea() in VS Code or another modern editor, you'll see the documented types and descriptions instantly. No need to jump to the function definition or guess what type is expected.

Key Takeaway: @param transforms your functions into self-documenting code that editors understand, reducing errors and improving the developer experience without needing TypeScript.