JavaScript Tutorial

Javascript Comments

The Javascript comment are the meaningful way to deliver message. It is used to explain Javascript code, any warnings or suggestions so that end user can easily understand the code.

These comments are ignored by the Javascript engine i.e embedded in the browser and are used to prevent execution of code is suitable for code testing.

Advantages of Javascript Comments

Following are the advantages of using javascript comments within our code:-

  • To make code easy to understand:- It can be used to elaborate the code so that the end user can easily understand the code.
  • To avoid unnecessary code:-  Sometimes, we add the code to perform some action. But after some time, there may be a need to disable that code. In such cases, it is better to use comments.

Types of Javascript Comments

There are two types of comments available in javascript:-

  • Single line comment:- These comments are written in one line represented by double forward slashes (//). It can be used before and after the statement.

  • Multi-line comment:- These comments can be written in multiple lines represented by a forward slash and backward slash with an asterisk(/* */).

It can be used before, after, and middle of a statement.

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

 

Test your JAVASCRIPT skills.

EXERCISE - 1

Test Questions 

JAVASCRIPT Quiz Test
Go back to Previous Course