CodesJava

Easy learning with example program codes

javascript comment tutorial


JavaScript comments are used to explain the JavaScript code logic. JavaScript comments are ignored by JavaScript translator. 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 end of the line will be ignored by JavaScript translator.

Syntax:

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

JavaScript Single-line Comment Example:

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

Output:

JS Bin on jsbin.com

JavaScript Multi-line Comment:

The Multi line comments start with forward slash with asterisk /* and end with asterisk with forward slash*/. Anything between /* and */ will be ignored by 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 codesjava.com");  
</script> 
</body> 
</html>

Output:

JS Bin on jsbin.com
 



Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap