Catalog / JSDoc Cheatsheet
JSDoc Cheatsheet
A quick reference guide for JSDoc, the industry standard for documenting JavaScript code. This cheatsheet provides syntax and examples for documenting functions, variables, types, and more.
Function Documentation
Basic Function Documentation
Use JSDoc comments |
|
Example:
|
Optional Parameters
|
An optional parameter of type string. |
|
An optional parameter of type number with a default value of 18. |
Parameter Types
|
A parameter of type string. |
|
A parameter of type number. |
|
A parameter of type boolean. |
|
A parameter of type object. |
|
A parameter that is an array of strings. |
Type Definitions & Variables
Type Definitions (@typedef)
Use |
|
Shorthand Syntax:
|
Documenting Variables
|
Specifies the type of a variable. |
|
Specifies the type of a constant variable. |
|
Examples of documenting variables with |
Importing Types
You can import types from other modules using the |
|
Advanced JSDoc Tags
Other Useful Tags
|
Documents that a function may throw an error. |
|
Indicates that a function is asynchronous. |
|
Marks a property or method as private. |
|
Indicates that a function or property is deprecated. |
|
References another function, class, or external resource. |
|
Explicitly defines a function or method. |
Code Examples with @example
Use the |
|
Linking to Other Documentation
You can create links to other parts of your documentation using the |
|
Class and Namespace Documentation
Class Documentation
Use the |
|
Namespace Documentation
Use the |
|
Renaming with @alias
Use the |
|