Create JSDoc Comments for JavaScript IntelliSense

Visual Studio 2015
 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Visual Studio 2017 Documentation. IntelliSense in Visual Studio displays information that you add to a script using standard JSDoc comments. You can use JSDoc comments to provide information about code elements such as functions, fields, and variables.

The following standard JSDoc comment tags are used by IntelliSense to display information about your code.

JSDoc tagSyntaxNotes
@deprecated@deprecated descriptionSpecifies a deprecated function or method.
@description@description descriptionSpecifies the description for a function or method.
@param@param {type} parameterNamedescriptionSpecifies information for a parameter in a function or method.

TypeScript also supports @paramTag.
@property@property {type} propertyNameSpecifies information, including a description, for either a field or member that's defined on an object.
@returns@returns {type}Specifies a return value.

For TypeScript, use @returnType instead of @returns.
@summary@summary descriptionSpecifies the description for a function or method (same as @description).
@type@type {type}Specifies the type for a constant or a variable.
@typedef@typedef {type} customTypeNameSpecifies a custom type.

Examples

The following example shows the use of the @description, @param, and @return JSDoc tags for a function named getArea.

/** @description Determines the area of a circle that has the specified radius parameter.  
 * @param {number} radius The radius of the circle.  
 * @return {number}  
 */  
function getArea(radius) {  
    var areaVal;  
    areaVal = Math.PI * radius * radius;  
    return areaVal;  
}  

In the preceding example, IntelliSense shows the description, parameter, and return information when you type the opening parenthesis for getArea.

IntelliSense information for a function

The following example shows how to use the @typedef tag with the @property tag.

/**  
  * @typedef {object} Weather  
  * @property {string} current The current weather.  
  */  
function getForecast(Weather) {  
}  
  
var w = new Weather();  

The following example shows the use of the @type JSDoc tags. As shown in this example, single asterisks (*) that follow the initial asterisk pair (**) are not required.

/**  
    @type {string}  
*/  
const RED = 'FF0000';  
  

The following example shows how to use the @deprecated JSDoc tag.

/**  
 * @deprecated since version 2.0  
 */  
function old() {  
}  

Show: