How to indicate param is optional using inline JSDoc?

studgeek picture studgeek · May 3, 2011 · Viewed 51.6k times · Source

According to the JSDoc wiki for @param you can indicate a @param is optional using

/**
    @param {String} [name]
*/
function getPerson(name) {
}

and you can indicate a param inline using

function getPerson(/**String*/ name) {
}

And I can combine them like the following, which works ok.

/**
    @param [name]
*/
function getPerson(/**String*/name) {
}

But I would like to know if there is a way to do it all inline if possible.

Answer

czerny picture czerny · Apr 4, 2015

From official documentation:

Optional parameter

An optional parameter named foo.

@param {number} [foo]
// or:
@param {number=} foo

An optional parameter foo with default value 1.

@param {number} [foo=1]