JavaScript Comment

The JavaScript comments are considered as the most meaningful way in order to deliver the messages. The JavaScript is used in order to add the additional information about the code, suggestions or warnings.

This is done in order to help the user to interpret the code very easily.

The JavaScript comments are generally ignored by the JavaScript engine i.e. it is embedded in the browser.

Types of JavaScript Comments

There are two types of comments in JavaScript.

  • Single-line Comment
  • Multi-line Comment

Advantages of JavaScript comments

There are many benefits of using the JavaScript Comment.

  • The main aim of the JavaScript comment is to make the code easy to understand - the comment can be used in order to elaborate the code so that the users can understand the code quickly
  • Next advantage is to avoid all the unnecessary codes - the JavaScript comment is also used in order to avoid any type of irrelevant codes. It can be sued in order to avoid the code from being executed. Sometimes we can also add the code in order to perform some action.

In case the case code has to be disabled then the same can be performed using the JavaScript comment. Whenever a code is required to be disabled it is always preferred to use the JavaScript comment.

Single-line Comment in JavaScript

The JavaScript single line comment is generally represented by double forward slashes (//) it can be used before and after the statement.

// It is single line comment
document.write("hello Java Portal India Pvt Ltd");

Multi-line Comment in JavaScript

In case of multiple line comment the single line comments can be added to it without any hassle. It is more convenient to use the multiple line comment. The multiple line comment is represented using the forward slashes with an asterisk and then the asterisk is followed by a forward slash. This comment can also be used before and after the statement.

/* this is startup company .
Java Portal India Pvt Ltd */
document.write("example of javascript multiline comment");