Like other programming languages, we can use Comments within our JavaScript code to for documentation or for easy understanding. Comments can be used before or after any line of code within the code.
Note that these comments are to be used within JavaScript codes only and should not be used outside the script area or in our html areas.
Single line comments we can place comment any where by adding // before the line. Here is an example.
<script type="text/javascript">
var msg="Welcome to plus2net";
document.write(msg);
// Display message through variable
</script>
We can place comments at the end of a line also.
<script type="text/javascript">
var msg="Welcome to plus2net";
document.write(msg); // Display message
</script>
Multiline comments
Comments can be extended to multiline also. Like this .
<script type="text/javascript">
/*
The below line will display
Welcome message to all
visitors of plus2net.com
*/
var msg="Welcome to plus2net";
document.write(msg);
</script>