JSDoc Example
Functions
/**
* This is a function.
*
* @param {string} n - A string param
* @return {string} A good string
*
* @example
*
* foo('hello')
*/
function foo(n) {
return n
}
Types
Type | Description |
---|---|
@param {string=} n |
Optional |
@param {string} [n] |
Optional |
@param {(string|number)} n |
Multiple types |
@param {*} n |
Any type |
@param {...string} n |
Repeatable arguments |
@param {string} [n="hi"] |
Optional with default |
@param {string[]} n |
Array of strings |
@return {Promise<string[]>} n |
Promise fulfilled by array of strings |
Variables
/**
* @type {number}
*/
var num = 1
/**
* @const {number}
*/
const num = 1
Typedef
/**
* A song
* @typedef {Object} Song
* @property {string} title - The title
* @property {string} artist - The artist
* @property {number} year - The year
*/
/**
* Plays a song
* @param {Song} song - The {@link Song} to be played
*/
function play(song) {}
Typedef Shorthand
/**
* A song
* @typedef Song
*/
/**
* Plays a song
* @param {Song} song - The {@link Song} to be played
*/
function play(song) {}
Importing types
/**
* @typedef {import('./Foo').default} Bar
*/
/**
* @param {Bar} x
*/
function test(x) {}
Other keywords
/**
* @throws {FooException}
* @private
* @deprecated
* @see
*
* @function
* @class
*/
Renaming
/*
* @alias Foo.bar
* @name Foo.bar
*/