What are the rules for commenting on code?

Here are some rules to help you achieve a happy medium: Rule 1: Comments should not duplicate the code. Rule 2: Good comments do not excuse unclear code. Rule 3: If you can’t write a clear comment, there may be a problem with the code. Rule 4: Comments should dispel confusion, not cause it. Rule 5: Explain unidiomatic code in comments.

Why is code commenting important?

serve as a reminder to change something in the future. Code commenting also becomes invaluable when you want to ‘comment out’ code. This is when you turn a block of code into a comment because you don’t want that code to be run, but you still want to keep it on hand in case you want to re-add it.

Should I remove commented code?

To keep your code clean and more readable, remove commented code, its already difficult to read programs as it is without having to read code that may or may not be significant. Yes, it is. Even you have debugging code that you do not want in your production release, you should not comment it out.

What are examples of useful comments in JavaScript?

In a sense, a legal note is the only example of truly useful comment. Last but not least, let’s see an example of some code with unnecessary comments. Here is a piece of JavaScript code that finds the largest number in an array. // Return the candidate number. As you can see, there are a bunch of comments in this piece of code.