Javascript comment
JavaScript comments are used to explain JavaScript code. It is used to add information about the code, warnings or suggestions so that end users easily understand the code.
Types of JavaScript comments
Two types of JavaScript comments:- Single-line Comment
- Multi-line Comment
Single-line Comment
Single-line comment is represented by double forward slashes (//). Any text between double forward slashes (//) and end of line will be ignored while program is executed. eg. Comment added before the statement.<!DOCTYPE html>
<html>
<body>
<script>
// single-line comment //
document.write("hello world");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
var a=10;
var b=20;
var c=a+b; //It add values of a and b variable
document.write(c); // print sum of 10 and 20
</script>
</body>
</html>
30
Multi-line comment
Multi-line comments can be used for single as well as multi-line comments. Multi-line comments start with /* and end with */. The text between them will be ignored by JavaScript. /* Write comment here */ Example<!DOCTYPE html>
<html>
<body>
<script>
/* It is multi-line comment.
It will not be displayed */
document.write ("Example of JavaScript multi line comment");
</script>
</body>
</html>