Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the standard way of adding documentation to a JavaScript function? [closed]

I'm looking at generating API docs for a JavaScript project. Does JavaScript have anything similar to Python's docstring?

function add(a, b) {
  /**
    Returns the sum of `a` and `b`.
  */
  return (a - 0) + (b - 0);
}
like image 586
Tim McNamara Avatar asked Nov 14 '10 23:11

Tim McNamara


People also ask

How do you document a function in JavaScript?

It follows a standard format. /** * [someFunction description] * @param {[type]} arg1 [description] * @param {[type]} arg2 [description] * @return {[type]} [description] */ var someFunction = function (arg1, arg2) { // Do something... }; Here's an example with an actual function, to help make it stick.

Which of the following statements is the correct way to define a function in JavaScript?

The most common way to define a function in JavaScript is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.

How do you call a function within a function in JavaScript?

To call a function inside another function, define the inner function inside the outer function and invoke it. When using the function keyword, the function gets hoisted to the top of the scope and can be called from anywhere inside of the outer function.


1 Answers

JSDoc is one way to do it.

/**
 * Adds two numbers.
 */
function add(a, b) {
    return a+b;
}
like image 97
icktoofay Avatar answered Sep 28 '22 08:09

icktoofay