Basic

You can specify the type of a parameter like following:

/**
 * Adds a user
 * @param {String} name the name of the user
 * @param {Number} age the age of the user
 * @return {Boolean} true if successful
 */
##
# Adds a user
# @param {String} name the name of the user
# @param {Number} age the age of the user
# @return {Boolean} true if successful

The result of the above comment:

Adds a user

Parameters

NameTypeDescription
nameString the name of the user
ageNumber the age of the user

Returns

NameTypeDescription
(Returns)Booleantrue if successful

Specifying options object

Often, JavaScript functions have an options object. You can add a comment for this like following:

/**
 * Defines a new property on an object.
 * @param {Object} object the object on which to define the property
 * @param {String} name the name of the property to be defined
 * @param {Object} descriptor the descriptor for the property
 * @param {Boolean} [descriptor.configurable=false] true if and only if the type of this property descriptor may be changed
 * @param [descriptor.value=undefined] the value associated with the property
 */
##
# Defines a new property on an object.
# @param {Object} object the object on which to define the property
# @param {String} name the name of the property to be defined
# @param {Object} descriptor the descriptor for the property
# @param {Boolean} [descriptor.configurable=false] true if and only if the type of this property descriptor may be changed
# @param [descriptor.value=undefined] the value associated with the property

The result of the above comment:

Defines a new property on an object.

Parameters

NameTypeDescription
objectObject the object on which to define the property
nameString the name of the property to be defined
descriptorObject the descriptor for the property
configurable=falseoptionalBoolean true if and only if the type of this property descriptor may be changed
value=undefinedoptional the value associated with the property

Returns

(Nothing)

Currently, options can be nested at the maximum third levels. (eg. user.name.first_name)

Specifying callback function

Using callback is the common pattern of JavaScript, especially in Node.js. You can add a comment for this like following:

/**
 * Asynchronous file open
 * @param {String} path the path to open
 * @param {String} flags flags for opening
 * @param {Number|String} [mode='0666'] file creation mode
 * @param {Function} [callback] the callback function
 * @param {Error} callback.error not null if an error is occurred
 * @param {Number} callback.fd a file descriptor
 */
##
# Asynchronous file open
# @param {String} path the path to open
# @param {String} flags flags for opening
# @param {Number|String} [mode='0666'] file creation mode
# @param {Function} [callback] the callback function
# @param {Error} callback.error not null if an error is occurred
# @param {Number} callback.fd a file descriptor

The result of the above comment:

Asynchronous file open

Parameters

NameTypeDescription
pathString the path to open
flagsString flags for opening
mode='0666'optionalNumber, String file creation mode
callbackoptionalFunction(error, fd) the callback function
errorError not null if an error is occurred
fdNumber a file descriptor

Returns

(Nothing)
Fork me on GitHub