Comments usually increase the code readability. JavaScript comments are categorized into two types:
These comments are indicated by double slashes(
//).
[html]
<script type="text/javascript">
//Inserting the heading tag h1
document.write("<h1>Welcome to SPLessons</h1>");
</script>
[/html]
Multi-line comments can be represented by (
/*...*/).
[c]
<script type="text/javascript">
/*The below code writes
Two headings and one paragraph
*/
Document.write("<h1>Hello World</h1>");
Document.write("<h2>Welcome to SPLessons<h2>");
Document.write("You are reading JavaScript Tutorial");
</script>
[/c]
Sometimes some browsers may not support JavaScript and display the code as page content itself. So, to hide the code, HTML comment tags(
<!-- ...... //--> ) are used. For example,
[html]
<html>
<body>
<script type="text/javascript">
<!-- document.write("Hello World"); //-->
</script>
</body>
</html>
[/html]
Other solution for this problem is to use
tags. In this case, any tags can be used except the script tags.
[html]
<noscript>
<p>This page requires a JavaScript enabled browser</p>
</noscript>
[/html]