Questions tagged [jsdoc]

JSDoc is a markup language for adding inline API documentation to JavaScript source code. This is distinct from the various tools that parse and manipulate code that follows the JSDoc syntax.

The JSDoc markup language is similar to the Javadoc syntax, used for documenting Java code, but is specialized to work with JavaScript's more dynamic syntax and therefore unique, as it is not completely compatible with Javadoc. However, like Javadoc, JSDoc allows the programmer to create doclets and tags which can then be translated into published output, like HTML or RTF.

Example:

/**
    Represents a book.
    @constructor
    @param {string} title - The title of the book.
    @param {string} author - The author of the book.
 */
function Book(title, author) {
}

The following annotations are commonly used in modern JSDoc, but the full list varies between implementations:

  • @param Documents a method parameter; a datatype indicator can be added between curly braces
  • @return Documents a return value
  • @constructor Marks a function as a constructor
  • @deprecated Marks a method as deprecated
  • @private Signifies that a method is private
  • @requires Describe a required resource.
  • @this Specifies the type of the object to which the keyword "this" refers within a function.
  • @throws Documents an exception thrown by a method
  • @exception Synonym for @throws
  • @author Developer's name
  • @version Provides the version number of a library
1697 questions
11
votes
5 answers

Is there a detailed documentation on how to create own jsdoc templates?

Short version: If I wanted to develop a completely new jsDoc template from scratch, what would I have to read to understand what jsDoc does, what interface my template must provide and what data I get to work with? Long version: I've been using…
codepearlex
  • 544
  • 4
  • 20
11
votes
1 answer

Is there an official order for JSDoc tags in documentation?

i am documenting a JavaScript API. I am following the google style guide but I found nothing about the order of the tags. I usually document a variable like this: /** * @description Radius of the circle * @private * @memberOf Circle * @type…
joaorodr84
  • 1,251
  • 2
  • 14
  • 33
11
votes
1 answer

How to use JSDoc3 to document nested namespaces

I'm having trouble using JSDoc3 to document code that's structured along these lines /** * @namespace MyNamespace.MySubNamespace */ (function (MyNamespace) { MyNamespace.MySubNamespace.Foo = { doSomething: function (someParam) { …
Julian A.
  • 10,928
  • 16
  • 67
  • 107
10
votes
2 answers

Questions about documenting nested array and object data with jsDoc

How do I format nested arrays and objects using jsdoc? This is my best guess: an_obj = { username1 : [ { param1 : "value 1-1-1", param2 : "value 1-1-2", optional_nested : "1-1--2" …
SystemicPlural
  • 5,629
  • 9
  • 49
  • 74
10
votes
1 answer

How to use JSDoc to document a Vue component with script setup?

I'm building a Vue library with TypeScript. I'd like to export the documentation of the components, like I do with ordinary functions. Previously we would do this: