Skip to main content

@param

Syntax

@param {type} name - description
@param {type} [name] - optional parameter
@param {type} [name=default] - optional with default value

Overview

@param documents a function parameter's name, type, and description. All three parts are optional, but providing at least a name is strongly recommended.

The parameter type may be any JavaScript built-in (string, number, boolean, Object, Array, …), a type expression, or a JSDoc namepath to a symbol defined elsewhere in your codebase.

Examples

Name only

/**
* @param somebody
*/
function sayHello(somebody) {
alert(`Hello ${somebody}`);
}

Name and type

/**
* @param {string} somebody
*/
function sayHello(somebody) {
alert(`Hello ${somebody}`);
}

Name, type, and description

/**
* @param {string} somebody - Somebody's name.
*/
function sayHello(somebody) {
alert(`Hello ${somebody}`);
}

Optional parameter

Wrap the name in [square brackets] to mark a parameter as optional:

/**
* @param {string} [somebody='World'] - Somebody's name.
*/
function sayHello(somebody = 'World') {
alert(`Hello ${somebody}`);
}

Multiple types

Use | to allow more than one type:

/**
* @param {string|string[]} names - One or more names.
*/
function greetAll(names) {}

Object properties

Document the properties of an Object parameter with dotted names:

/**
* @param {Object} employee - The employee.
* @param {string} employee.name - The employee's name.
* @param {number} employee.department - The employee's department code.
*/
function hire(employee) {}

Repeatable parameter

Prefix the type with ... to indicate the parameter is repeatable (rest parameter):

/**
* @param {...string} names - One or more names.
*/
function greetAll(...names) {}

Destructured parameter

/**
* @param {Object} options
* @param {string} options.host - The server hostname.
* @param {number} [options.port=3000] - The server port.
*/
function connect({ host, port = 3000 }) {}

See also

Official reference: jsdoc.app/tags-param