comment types in JavaScript

The blog describes how to add comments in JavaScript. The JavaScript comments are helpful more to developers beacuse of below given points

  • JavaScript Comments allows to add related information about the written code or function getting called in the program
  • JavaScript Comments could be helpful in providing the program overview to help developers interpret the code logic
  • JavaScript Comments are useful when developers need to try multiple approaches to build a optimal solution for the problem
  • JavaScript Comments are useful to add Warnings
  • JavaScript Comments are useful when multiple developers work on the same program file

JavaScript Comments Types

The JavaScript Comments can be classified into 2 types

  • Single -Line Comments : The single -line comments are useful to provide the meaning for the written code to help in interpreting the logic .The single -line comments are enabled using double forward slashes (//) .
var length=10;                         // define length
var height=20;                         //define height
var area= length * height             // calcualtes area   
document.write(area);                //prints area as 200
  • Multi-Line Comments : The multi-line comments are useful when we need to provide more details , add specific guidelines to make it more readable and understandable. the multi -line comments are enabled using forward slash with asterisk then asterisk with forward slash /* Add Comments Here */
/* The program define the lenght and height .
   Calcualtes the Area by multiplying lenght * height */

var length=10;                         
var height=20;                         
var area= length * height