Show Menu
Cheatography

JSDoc

Type defini­tions

Boolean
{boolean} name
true/false
Integer
{number} name
0
Float
{number} name
0.0
Object
{Object} name
Specif­ied­Object
{Custo­mName} name
see @typedef
Array
{Array} name
[]
Array of Types
{Type[]} name
{string[]}
String
{string} name
'test'
Optional string
{string} [name]
Optional string default value
{string} [name=­test]
 

@state­ments

@param {type} name
Defines a parameter
@const­ructor
Defines a constr­uctor
@depre­cated
Function is deprecated
@return {type}
Defines return type

Typedef

/**
* @typedef ObjectOne
* @type {Object}
* @property {number} id
* @property {string} name
*/
 

Param example

/**
* @param {string} one
* @param {number} two
*/
function x( one, two ) {}

Array with types example

/**
* @param {string[]} ones
*/
function x( ones ) {}

Optional param example

/**
* @param {string} one
* @param {number} [two]
*/
function x( one, two ) {
two = two || 0;
}

Optional param default value

/**
* @param {string} one
* @param {number} [two=121]
*/
function x( one, two ) {
two = two || 121;
}

Multiple types

/**
* @param {string|string[]} one
*/
function x( one, two ) {}

Detailed object

/**
* @param {ObjectOne} one
*
* @typedef ObjectOne
* @type {Object}
* @property {number} id
* @property {string} name
*/
function x( one ) {
one.id;
one.name;
}

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Closure JSDoc Cheat Sheet