1. Home
  2. Docs
  3. Scripting Language
  4. Client Side Scripting
  5. Comments

Comments

Introduction

JavaScript comments can be used to explain JavaScript code, and to make it more readable JavaScript comments can also be used to prevent execution, when testing alternative code. There are 2 types of comments

  • Single Line Comments
  • Multi Line Comments

For your kind information

It is most common to use single line comments. Block comments are often used for formal documentation


Single Line Comments

Single line comments start with // Any text between // and the end of the line will be ignored by JavaScript (will not be executed).

//var name="Zeny Gupta";

Single line comment also use at the end of each line to explain the code.

var firstNumber = 50; // Declare firstNumber, and assign 50
var secondNumber 40; // Declare secondNumber, and assign 40
// Declare sum and assign sum of firstNumber and secondNumber 
var sum = firstNumber + secondNumber;

Multi-line Comments

Multi-line comments start with / and end with /.Any text between /” and “/ will be ignored by JavaScript.

/*
Declare firstNumber, give it the value of 50
Declare secondNumber, give it the value of 40.
Declare sum and assign sum of firstNumber and second Number.
*/
var firstNumber = 50;
var secondNumber = 40;
var total= firstNumber + secondNumber;
Was this article helpful to you? Yes No

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *