JavaScript comments
Developers use JavaScript comments to explain their JavaScript code not only to themselves but also to other fellow developers. It is a good practice to write comments as you code.
With the help of JavaScript comments, we can be preventing execution when testing alternative code.
Example: Commenting all code
// The code below won't execute, as it is marked as a comment, preventing its execution // var num3 = 5 + 6;
Single line comments
Single line comments start with //.
Example
// This is a single line comment var num1 = 1 + 2; var num2 = 3 + 4; // This is an inline comment
Multi-line comments
Multi-line comments start with /* and end with */.
Example: 1
/* When you have a lot to explain, use multi-line comments like this */ var num4 = 7 + 8;
Example: 2
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript multi-line comments Example</h2>
<p> a, b, and c are variables.</p>
<p id="test"></p>
<script>
var a = 7;
var b = 10;
var c = a + b;
/* where a, b, and c, are three variables
and declared these variables with the var keyword.
*/
document.getElementById("test").innerHTML =
"The value of c is: " + c;
</script>
</body>
</html>