JavaScript - Comments and Syntax

Normally in JavaScript the comments are treated as text between //. Multiple line comments are treated as the text between /* ans */

Comments in JavaScript

  • Normally in JavaScript the comments are treated as text between //.
  • Multiple line comments are treated as the text between /* ans */
  • Comments are required to make code understandable, we don't have to think we are not only the coder, programmer & expert. If another engineer or developer check any part of code then S/He should know what is that code and why that code exist. So it's better to put comments while doing coding.

HTML / JS Code For Single Line Comment

<html>
 <head>
 </head>
 <body>
  <script language="javascript" type="text/javascript">
  document.write("Hello World!!"); //prints the hello world!!
  </script>
 </body>
</html>

Output

This means that there will not be any change in the output using the comments.

HTML /JS Code For Multiple Line Comment

<html>
 <head>
 </head>
 <body>
  <script language="javascript" type="text/javascript">
  document.write("Hello World!!"); /* prints the 
hello world!! program */
  </script>
 </body>
</html>

Output

Again the output remain same while using multiple line comments in JavaScript.

You May Also Like...

Socialize with Us