JsDoc Cheat Sheet

About

JavaScript Documentation Tool (JSDoc) 1) is a tool that parses inline documentation in JavaScript source files, and produces an documentation of the JavaScript code.

JSDoc is based on javadoc tool that was created for the same purpose for the Java programming language.

Tag

Variable (MemberOf / Full qualified name)

/**
 * @memberOf   myLib
 * or
 * @name       myLib.MyDynamicallyLoadedModule
 */
var MyDynamicallyLoadedModule = {};

Object (Property)

  • Defining the properties of an object
/**
* @var {{value: string,default: string}} value
*/
let value;
/**
 * Test interface
 * @typedef {Object} Type
 * @property {String} tString - I'm a string
 * @property {Boolean} tBoolean - I'm a boolean
 * @property {Number} [tNumber=100] - I'm a number with a default value of 100
 * @property {Function} tFunction - I'm a function
 */

Object as Map

You can also define your object as being a set between a key type and a value type 2)

/**
 * A map-like object that maps arbitrary `string` properties to `number`s.
 *
 * @type {Object.<string, number>}
 */
var stringToNumber;
 
/** @type {Object.<number, object>} */
var arrayLike;

Global Variable

Exactly one line by global as describe below at the top of your file

/* global d3 */
/* global $ */

Function (param, return)

/**
 * @param {Type} someParam
 * @return {undefined} 
 */
function testFunction(someParam) {
  //
}
/**
* @param myParam1
* @param {string=} myParam2 - an optional parameter
* @param {string} [somebody] - Somebody is an optional parameter
*/
function loadDocs(myParam1, myParam2){}

Class (Static, augtments, …

/**
 *  @class MyView
 *  @augments Backbone.View
 *  @static 
*/

fileoverview

example:

/**
 * @fileoverview Search developers.google.com/web for articles tagged
 * "Headless Chrome" and scrape results from the results page.
 */

for

Javascript - For Statement

for (/** @type {MyType} */ const myVar of myArray) {
    // ...
}

Prototype

Library

Type checking with JsDoc and Typescript

Documentation / Reference


Powered by ComboStrap