📑JSDoc

Functions

/**
 * This is a function.
 *
 * @param {string} n - A string param
 * @param {string} [o] - A optional string param
 * @param {string} [d=DefaultValue] - A optional string param
 * @return {string} A good string
 *
 * @example
 *
 *     foo('hello')
 */

function foo(n, o, d) {
  return n
}

Types

AnnotationNote
@param {string=} nOptional
@param {string} [n]Optional
@param {(string|number)} nMultiple types
@param {*} nAny type
@param {...string} nRepeatable arguments
@param {string} [n="hi"]Optional with default
@param {string[]} nArray of strings
@return {Promise<string[]>} nPromise fulfilled by array of strings

Variables

/**
 * @type {number}
 */
var FOO = 1
/**
 * @const {number}
 */
const FOO = 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) {}

Shorthand

/**
 * A song
 * @typedef {{title: string, artist: string, year: number}} Song
 */
/**
 * Plays a song
 * @param {Song} song - The {@link Song} to be played
 */

function play(song) {}

Other keywords

/**
 * @throws {FooException}
 * @async
 * @private
 * @deprecated
 * @see
 *
 * @function
 * @class
 */

Importing types

/**
 * @typedef {import('./Foo').default} Bar
 */

// or

/** @import { Bar } from "./Foo.js" */

/**
 * @param {Bar} x
 */

function test(x) {}