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);
}
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.
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.
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.
JSDoc is one way to do it.
/**
* Adds two numbers.
*/
function add(a, b) {
return a+b;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With