JavaScript Comments
Like other programming languages, we can also provide comments in JavaScript. The commented code or text will not be executed. Comments are generally used to make the code readable and understandable to the developers revisiting the code. We can provide single-line comments and Multi-line comments in JavaScript.
Single-Line Comments in JavaScript
Single-Line comments are started with double slashes (//) and there is no need for anything at the end of the single-line comment.
//This is a Single-Line Comment.
document.write(''Welcome to JavaScript");
Multi-Line Comments in JavaScript
Multi-Line Comments are used to comment on multiple lines of text or code to avoid execution. Multi-Line Comments are enclosed within (/* and */). Multi-Line Comments are generally used for formal documentation of the code.
/* This is Comment-1.
This is Comment-2.
This is Comment-3.
*/
document.write(''Welcome to JavaScript");
Example
<HTML>
<HEAD>
<title>Comments
Demo</title>
</HEAD>
<BODY bgcolor='yellow'>
<script>
//Single-Line
Comment
for(var i=0;i<2;i++)
{
document.write('Welcome To JavaScript<br>');
}
/*
Multi-line Comment
There can be multiple line commented within
multi line comments
*/
</script>
</BODY>
</HTML>