There are two types of Javascript comments.
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.");
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;
document.write(productSellingCost);
//var distributorAmount = (productSellingCost*0.1);
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");
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){
if(x>y){
document.write("X is greater than Y.");
}else{
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);