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.
Advantages of using JavaScript comments
- Conveying To the point information for both users(readers) and developers in terms of code
- 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
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 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.