Document function parameters, return values, and exceptions
@param {type} name Description/**
* @param {number} x - The first number
* @param {number} y - The second number
* @param {Object} [options] - Optional configuration
* @param {boolean} [options.strict=false] - Use strict mode
*/
function calculate(x, y, options = {}) {
// implementation
}@returns {type} Description/**
* @param {number[]} numbers - Array of numbers
* @returns {number} The sum of all numbers
* @returns {null} Returns null if array is empty
*/
function sum(numbers) {
if (numbers.length === 0) return null;
return numbers.reduce((a, b) => a + b, 0);
}@throws {ErrorType} Description/**
* @param {string} email - User email address
* @throws {TypeError} When email is not a string
* @throws {Error} When email format is invalid
*/
function validateEmail(email) {
if (typeof email !== 'string') {
throw new TypeError('Email must be a string');
}
if (!email.includes('@')) {
throw new Error('Invalid email format');
}
}@yields {type} Description/**
* @generator
* @yields {number} The next number in the Fibonacci sequence
* @returns {Generator<number, void, unknown>}
*/
function* fibonacci() {
let a = 0, b = 1;
while (true) {
yield a;
[a, b] = [b, a + b];
}
}