JavaScript : Comments

Code written within comments are not processed by the interpreter. Comments are good way to write notations to explain what a script does. JavaScript supports the following two different ways of commenting, single line comment and multiple line comments.

w3r video tutorialsWatch write your first JavaScript video tutorial.

Single line comment

// This is a single line comment.

Example of JavaScript single line comments

<script type="text/javascript">
// This is a single line comment
document.write("We are learning JavaScript single line comment");
//document.write("Good Morning.");
</script>

Multiple line comments

In JavaScript multi line comments start with /* and end with */.

Example of JavaScript multiple line comments

<script type="text/javascript">
/* Multiple line comments start here
document.write("Good Morning");
Multiple line comments end here*/
document.write("We are learning JavaScript multiple line comments.");
</script>

Example of comments at the end of a line

<script type="text/javascript">
var empcode // declaring employee code
var empname // declaring employee name
alert("We are learning how to put comments at the end of a line");
</script>