JavaScript Comments
Comments are annotations in the source code of a program that are ignored by compilers or interpreters, and therefore have no effect on the actual output of the code. Usually, comments are used to add information about the code, warnings or suggestions so that end user can easily interpret the code. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.There are two types of comments in JavaScript:
- Single-line Comment
- Multi-line Comment
Single-line Comment
To create a single line comment in JavaScript, you place two slashes "//" in front of the code or text you wish to have the JavaScript interpreter ignore.
//This is a single line comment
var pi = 3.14; // Declare pi, give it the value of 3.14
example
<script>
// This is single line comment
document.write("First line....");
</script>
Multi-line Comment
Multi-line Comment or Block Comment is represented by forward slash with asterisk ( /*) then asterisk with forward slash(*/).
/* This is a
Multi line comment*/
example
<script>
/* Inside multiple line comments
alert("Wont see this message...");
Multiple line comments end here*/
alert("Here is the message");
</script>
Related Topics