Comments in JavaScript

Comments in our JavaScript file are used for the understanding of our JavaScript code . The comments does not displayed in output. They are just create for easiness in understand in the code to read it update it or check it again.

The Single Line Comments

In JavaScript single line comments start with //. Example of single line comments is given.

<script ...>
// This is comment 1
document.getElementById("demo").innerHTML = "Hello World";
// This is comment 2
document.getElementById("demo1").innerHTML = "Hello World";

The Multi-line Comments

In JavaScript Multi-line comments start with /* and end with */. An example of Multi-line comments is given with source code.

<script ...>
The code given is targeting the HTML element while
id demo is used to access the HTML element. This is
multi-line comment.
document.getElementById("demo").innerHTML = "Hello World";
document.getElementById("demo1").innerHTML = "Hello World";

Advantages of comments.

Comments play an important role in programming. They make the code easy to understand.For example if in some office programmer makes a project and give its documentations to another programmer. Without comments in the projects it will be really very difficult for the other programmer to understand its documentation. And comments also not shown in the out put so there is no chance to make interruption in the expected out put of the code.


Use the comments in your code. It is very helpful.

The Best

Comment here

If you have any query, if you want to know something about any of technical course related to computer science field, if you have any suggestion about relevant to uploaded content or if you anything wrong here (any mistake in content) than please contact us. Keep in mind, comment should be according to community guidelines.