Every program or application needs a good programmer documentation for any software developer that have access to understand what each line of code does. Also understanding how to insert JavaScript comment or how to insert a comment that has more than one line is very important. With comment, you can be able to tell the viewer of your source code what it is all about.
In this brief post, you will learn how to use JavaScript single line comment and JavaScript multiline comment alongside examples.
Comment is referred to as non-executable string of characters. It is through comment that codes or script can be explained in such a way that everyone that have access to the source code will have a better understanding and flow of the program.
In JavaScript, we have different types of comments and these are:
- Singe line comment
- Multiline comment
What is single line in JavaScript
As the name implies, single line comment applies to a single line in the source code.
JavaScript single line comment syntax
JavaScript single line comment is denoted by:
//comment content comes here
What is multiline in JavaScript
Multiline comment as it implies applies to more than one line in the source code.
JavaScript multiline comment syntax
The JavaScript multiline comment is denoted by:
/* comment content goes here */
The advantages of comments in web development cannot be overemphasized. Some of its advantages are:
- It makes codes to be understandable by anyone that view it
- It can be used to comment out irrelevant parts of codes.
Example of javascript multiline comment
Here is a simple demonstration of multiline JavaScript.
<script>
function(){
/*var a;
var b;*/
}
</script>
Example of javascript single comment
Here is a simple demonstration of single line JavaScript.
<script>
function(){
//var a;
//var b;
}
</script>