JavaScript – Comments and Syntax

Comments and Syntax

Comments in JavaScript

  • Normally in JavaScript, the comments are treated as text between //.
  • Multiple line comments are treated as the text between /* and */
  • 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 the code then S/He should know what is that code and why that code exists. So it’s better to put comments while doing the 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 remains the same while using multiple line comments in JavaScript.

TutsMaster.org

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.