Improve this page

@example

Tag type: block tag

TSDoc standardization: extended

Indicates a documentation section that should be presented as an example illustrating how to use the API. It may include a code sample.

Usage example:

/**
 * Adds two numbers together.
 *
 * @remarks
 * Use this function to perform example addition.
 *
 * @example
 * Here's a simple example:
 * ```
 * // Prints "2":
 * console.log(add(1,1));
 * ```
 *
 * @example
 * Here's an example with negative numbers:
 * ```
 * // Prints "0":
 * console.log(add(1,-1));
 * ```
 *
 * @param x - the first number to add
 * @param y - the second number to add
 * @public
 */
export function add(x: number, y: number): number {
  return x + y;
}

API Documenter will number the example sections automatically. The output might look like this:

add() function

Adds two numbers together.

Signature:

export declare function add(x: number, y: number): number;

Parameters

Parameter Type Description
x number the first number to add
y number the second number to add

Returns:

number

Remarks

Use this function to perform example addition.

Example 1

Here’s a simple example:

// Prints "2":
console.log(add(1,1));

Example 2

Here’s an example with negative numbers:

// Prints "0":
console.log(add(1,-1));

See also