JavaScript Comments

There are two types of Javascript comments.

  1. Single line comment
  2. Multi line comment

JavaScript Single line Comment

Javascript single-line comment can be done by double forward slashes (//). Javascript can not execute the text that lies between (//) and the end of the line.

Let us add a single-line comment for the developer's hint.

Source Code

            // It is single line comment  
document.write("I have learned single line comment.");          
Try it now

Disabling Javascript Source Code

Let us add a single-line comment for disabling the Javascript statement.

Source Code

            var productionCost = 100;
var transportCharge = 200;
var profitAmount = 50;
var productSellingCost = productionCost + transportCharge + profitAmout;
//var distributorAmount = (productSellingCost*0.1);          
Try it now

Javascript Multi Line Comment

Multi-line comment starts with /* and ends with*/. It is used to add a single line as well multi-line comment.

Multi-line comment is used to provide the developer's code hint:

Source Code

            /* It is a multi-line comment that will be used for single as well as multi-line comments. 
The commented line can not be displayed  
document.write("Learn Javascript multi-line comment");          
Try it now

Disabling Source Code Using Multi Line

Multi-line comment is also used for disabling unnecessary sources of code.

Source Code

            function addNumber(x, y) {
  return x + y;
//used to comment unnecessory source code
function basicTest(x,y){
function basicTest(x,y){
document.write("X is greater than Y.");
document.write("X is smaller than Y.");
var result = addNumber(10, 20);
//var testResult = basicTest(15>50); Signle line comment
//document.write(testResult); single line comment
document.write("Summation of two number : " + result);          
Try it now

Web Tutorials

Javascript Comments
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4