Skip to main content

How To Write Comments in JavaScript

JavaScript comments can be used to describe and explain JavaScript code, and to make the code it more readable and easy understandable.

Comments in JavaScript

Comment is nothing but it is a statement, Comments are not executed unlike the code on browser window.The javascript interpreter ignores the comments and continues execution till the end of file, when it encounters any comments.

Comment is also used to add information about the code, warnings or suggestions so that the end user or other developer can easily interpret the code.

There are 3-types of comments in JavaScript :

  1. Single-Line Comment

  2. Multi-Line Comment

  3. ScriptDoc Comment

# Types of JavaScript Comments:

1.) Single-Line Comment : A single-line comment is represented by double forward slashes (//), It can be used before any statement.

 ➤ Example :

<script>
   // Write on browser
        document.write("Hello Javascript!");
   // Write text an <h2> Heading
 document.write("<h2> Hello Javascript! </h2>");  
 </script>
Output :

Hello Javascript!

Hello Javascript!


2.) Multi-Line Comment : Multiline comments are used for large text descriptions of code.

  • A multi-line comment is represented by forward slash ( / )with asterisk (*) then asterisk with forward slash.

  • Multiple-line comments start with forward slash and asterisk (/*), and end with the reverse asterisk and forward slash (*/).

  • Note : It is also used for single-line comment.

 ➤ Example :

<script>
   /*
      First line: Write Simple write
      Second line: Write text an <h2> Heading
   */
     document.write("Hello World!");
     document.write("<h2> Hello World! </h2>");  
 </script>
Output :

Hello World!

Hello World!


3.) ScriptDoc Comment / JavaScript Documentation Comment :

  • ScriptDoc is JavaScript documentation technique, It is also known as JDC(JavaScript Documentation Comment).

  • It's good habit to write remarks, arguments or notes etc. on JavaScript.

 ➤ Syntax :

    In JavaScript documentation style comment you can write following way :

<script>
   /** 
    * ScriptDoc technique to write comment
    * @TagName Description
    * @author   
    * @version 
    * ….
  **/ 
 </script>

Let's see the example of JavaScript Documentation Comment

 ➤ Example :

<script>
   /** 
    * Multiplication of two numbers 
    * @param {Number} a 
    * @param {Number} b 
    * @return {String} mult 
  **/ 
  function multiplication(a, b)
  { 
     mult = a * b;
     return "Output is : "+ mult.toString(); 
  }
  result = multiplication(7, 10);
  document.write(result);
</script>
Output :

Output is :70


ScriptDoc provides the many list of tags for documentation technique. There are few tags of ScriptDoc :

Tag Description
@author Author-name [ email ] Author of JavaScript file, functions, class.
@classDescription Description Brief description of the Class.
@constructor Specifies this function is a constructor.
@example Example-code Describe a real example for how to use this function.
@id identifierName Specifies ID for unique identification.
@inherits inherit_class Specifies inherited class.
@memberOf Class function, Property is member of specified class.
@method Specifies the method name in class.
@exception { Exception } Specifies exception type that throw this function.
@namespace namespaceName Specifies the external library file.
@param { Type } ParameterName Parameter-Description Specifies parameter of this function.
@private Indicate that a class or function is private.
@projectDescription Description Specifies on top of the page that describe the description of this file.
@property {Type} Indicate that specified property are instance of the class.
@return {Type} Returns-Description Specifies the return values of a function.
@type {Type} Specify the data type of this property.
@version Version-Number Specify the version number of file.

Comments

Popular Posts

How to remove the date and .html from every blogger post url

#Remove date and .html from blogger post url A Common search term which every blogger search is How to Remove Date From Blogger Post URL or how do I remove date from blogger permalink? Follow the steps below and then date and .html will be removed from the URL of your blogger post. Step 1 : Login to your Blogger blog and select Theme / Template. Step 2 : Click on Edit HTML and paste the below code just above the </head> tag let's see code :   ➤ Code : mycode.js; Copy code <script type='text/javascript' > //<![CDATA[ // BloggerJS v0.3.1 var urlTotal,nextPageToken,postsDatePrefix=!1,accessOnly=!1,useApiV3=!1,apiKey="",blogId="",postsOrPages=["pages","posts"],jsonIndex=1,secondRequest=!0,feedPriority=0,amp="&"[0];function urlVal(){var e=window.location.pathname,t=e.length;return...

Django static files not working when debug false || debug true

# Django static and media files not working when debug is false In this article you will learn how to fix problem of not loading static files and media in Django even the DEBUG is FALSE. This is the easiest and safest solution. # Problem: Django static and media files not working when debug is false  ➤ Code: settings.py DEBUG = False #True ALLOWED_HOSTS = [ '*' ] #Host name # Problem Fix: Let's see, How you can fix the problem of Django static and media files not working when DEBUB = False : 1.)First way: devserver in insecure mode If you still need to server static locally ( e.g. for testing without debug ) you can run devserver in insecure mode: python manage.py runserver --insecure --insecure: it means you can run serve...

Django not able to find static files[Solved]

# Django static files not working In this article, you will learn how to fix the problem of not loading static files. This is the easiest and safest solution. In the new version of Django 3.1 and above the settings.py file uses PATH instead of OS to deal with the directory structure. So all the code, we wrote for our static dirs and things like that will no longer work unless we import os at the top of our settings.py file.. Note : This article related to DEBUG = True , if you have problems with DEBUG = False then you can follow this article; Static files not working when DEGUB= False . Have fun! Let's follow a few steps and, solve the problem of not loading Django static files: Step 1 : Check that "BASE_DIR" is defined in your project settings.py , if not then define it  ➤ Code: settings.py import os BASE_DIR = ...