JSDoc Cheat Sheet

A cheat sheet in English by SamanthaAdrichem

JSDoc

13,981 views 3,190 downloads 3 May 2017 History
3.7 avg · 0 ratings

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
'­tes­t'
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;
	}

Badges

Nice Cheat Sheet Good Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.