EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials TypeScript Tutorial TypeScript JSDoc
 

TypeScript JSDoc

Updated April 10, 2023

TypeScript JSDoc

 

 

Introduction to TypeScript JSDoc

The Application Programming Interface documentation generator for TypeScript is JSDoc. In which the documentation comments are directly added to the source code on the right side of the code itself and there is a JSDoc tool to scan the source code and generate the HTML documentation and the purpose of JSDoc is to document the TypeScript library and by using JSDoc modules, classes, namespaces, methods, method parameters etc. can be documented and each comment in a JSDoc should begin with /** and end with */ otherwise the comment will not be recognized by the JSDoc parser and those beginning with /* or /*** will be ignored by the parser.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax to declare a comment in TypeScript class:

** comment1
*comment2
*comment3
*commentn
*/

Where comment1, comment2, comment3, commentn are the comments to be included in a TypeScript program.

Working of JSDoc or Comments in TypeScript

  • The Application Programming Interface documentation generator for TypeScript is JSDoc in which the documentation comments are directly added to the source code on the right side of the code itself.
  • There is a JSDoc tool to scan the source code and generate the HTML documentation.
  • The purpose of JSDoc is to document the TypeScript library and by using JSDoc modules, classes, namespaces, methods, method parameters etc. can be documented.
  • Each comment in a JSDoc should begin with /** and end with */ otherwise the comment will not be recognized by the JSDoc parser and those beginning with /* or /*** will be ignored by the parser.

Examples of TypeScript JSDoc

Given below are the examples of TypeScript JSDoc:

Example #1

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the power of a given number and display the output on the screen.

Code:

/** defining an anonymous function using arrow function to compute the power of a number and display the result as the output on the screen
*/
let power = (firstnum:number, secondnum:number) : number => {
return Math.pow(firstnum, secondnum);
}
console.log('The result when the given number is raised to the power of 2 is: ');
console.log(power(10,2));

Output:

TypeScript JSDoc 1

In the above program, the comments section is described between the symbols /** and */. Then we are defining an anonymous function using arrow function to compute the power of given number and display the result as the output on the screen.

Example #2

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the power of a given number and display the output on the screen.

Code:

/**
*Computes the power of a given number
*@constructor
*@param {number} firstnum – The number whose power raised to 2 must be found
*@param {number} secondtnum – The number 2 to which the given number must be raised to.
*/
function power(firstnum:number, secondnum:number)
{
let result = Math.pow(firstnum, secondnum);
return result;
}
console.log('The result when the given number is raised to the power of 2 is: ');
console.log(power(10,2));

Output:

TypeScript JSDoc 2

In the above program, the comments section is described between the symbols /** and */ in which we have defined that there is a function using @constructor and the parameters are defined with their datatypes using @param. Then we are defining a function using to compute the power of given number and display the result as the output on the screen.

Example #3

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the square root of a given number and display the output on the screen.

Code:

/**
*Computes the square root of a given number
*@constructor
*@param {number} firstnum – The number whose square root must be found
*/
function squareroot(firstnum:number)
{
let result = Math.sqrt(firstnum);
return result;
}
console.log("The square root of the given number is:\n", squareroot(4);

Output:

square root

In the above program, the comments section is described between the symbols /** and */ in which we have defined that there is a function using @constructor and the parameters are defined with their datatypes using @param. Then we are defining a function to compute the square root of a given number and display the result as the output on the screen.

Example #4

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the factorial of a given number and display the output on the screen.

Code:

/**
*Computes the factorial of a given number
*@constructor
*@param {number} firstnum – The number whose factorial must be found
*/
var fact:number = 1;
function factorial(firstnum:number)
{
for(let u =firstnum; u>=1; u--)
{
fact = fact * u;
}
return fact;
}
console.log("The factorial of the given number is:\n", factorial(5);

Output:

functionality of the program

In the above program, the comments section is described between the symbols /** and */ in which we have defined that there is a function using @constructor and the parameters are defined with their datatypes using @param. Then we are defining a function to compute the factorial of a given number and display the result as the output on the screen.

Rules and Regulations for JSDoc or Comments

Given below are the Rules and Regulations for JSDoc or Comments in TypeScript:

  • A comment in TypeScript should begin with the symbol /**.
  • A comment in TypeScript should end with symbol */.
  • Comments beginning or ending with other symbols are not recognized by the JSDoc parser.
  • A function must be represented within the comment section by using @constructor.
  • The parameters must be represented along with their data types within the comment section by using @param followed by their data type in curly brackets.

Recommended Articles

We hope that this EDUCBA information on “TypeScript JSDoc” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. TypeScript let
  2. TypeScript typeof
  3. TypeScript Generic
  4. TypeScript Versions

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW