Quick Links
Not all JavaScript statements are “executed”. Code after a double slash //, or between /* and */, is treated as a comment. JavaScript Comments are ignored, and are not executed.
Advantages of JavaScript Comments
There are mainly two advantages of JavaScript comment.
- To make code easy to understand It can be used to elaborate the code so that end user can easily understand the code.
- To avoid the unnecessary code It can also be used to avoid the code being executed. Sometimes, we add the code to perform some action. But after sometime, there may be need to disable the code. In such case, it is better to use comments.
Types of JavaScript Comments
There are two types of comment in JavaScript.
- Single-line Comment
- Multi-line Comment
Single line Comment
Single line comments use double slashes.
<script>
// It is single line comment
document.write("hello Learner's");
</script>
Let’s see the example of single-line comment i.e. added after the statement.
<script>
var a=10;
var b=20;
var c=a+b;//It adds values of a and b variable
document.write(c);//prints sum of 10 and 20
</script>
Multi line Comment
Everything you write between /*and */ will be considered as a multi-line comment.
<script>
/* It is multi line comment.
It will not be displayed */
document.write("example of javascript multiline comment");
</script>
Welcome to JavaScript!
JavaScript in Detail
External JavaScript
Syntax in JavaScript
Comments in JavaScript
Variables in JavaScript
Operators in JavaScript