What are JavaScript Comments?

JavaScript Comments :These are side information added to each code so that they convey the right message about the code identification especially to readers enhancing the overall process of coding only.

These JavaScript comments are completely ignored by the web browsers to have any impact on the overall page development.

Advantages of using JavaScript comments

  1. Conveying To the point information for both users(readers) and developers in terms of code
  2. Following standard protocols and is quite helpful when disabling specific code in case you have to disable it.

Types of JavaScript Comments:-

There are two types of comments in JavaScript.

  • Single-line Comment
  • Multi-line Comment

Single line Comment
  • JavaScript Single Line Comment is represented by Double forward slashes (//).
  • They are used at both before and after the statements

Single line JavaScript Comment

JavaScript Multi line Comment
  • Multi Line comments are represented by Single forward slash (/) with asterik on the interior at both starting and at end.
  • This can be used in Single and Multiple line comments both

JavaScript Multiple Line comments

Single Line comments are mostly used whereas multiple lines are used in formal documentation of specific project.

JavaScript Comment Best Practices

  • All JavaScript Comments must have readability to avoid mixing them with code at all stages
  • Comments must have separate spaces from the source code with different colors if possible
  • Comments must be continuous as you move along writing code for fresher perspective simultaneously better understanding towards the project too.
  • Their use in Code testing is remarkable by using them in the beginning and ending of the code to check whether the specific code is functioning or not.
  • When the code is lengthy with lots of checks these comments becomes the fundamentals for finding bugs and errors respectively. Hence right comments must be added at necessary points.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *