Javascript Comment

JavaScript comments are used to explain the JavaScript code logic. JavaScript comments are ignored by JavaScript translators. It makes JavaScript code more readable.

Types of JavaScript comments:

1. Single-line Comment
2. Multi-line Comment

JavaScript Single-line Comment:

The double forward slashes (//) are used for Single line comments. Anything between // to the end of the line will be ignored by the JavaScript translator.

Syntax:

<script>
//Single line comment
JavaScript Code
</script>

JavaScript Single-line Comment Example:

<html>
<body>
<script>
// Single line comment
document.write("Hello w3schools.com");
</script>
</body>
</html>

JavaScript Multi-line Comment:

The Multi-line comments start with a forward slash with an asterisk /* and end with an asterisk with a forward slash*/. Anything between /* and */ will be ignored by the JavaScript translator. It can be used to comment single as well as multiple lines.

Syntax:

<script>
/* Multi-line comment
This line will not execute */
JavaScript Code
</script>

JavaScript Multi-line Comment Example:

<html>
<body>
<script>
/* Multi-line comment
This line will not execute */
document.write("Hello w3schools.com");
</script>
</body>
</html>