JavaScript – How to Differentiate Informative Comments from Commented Out Code?

commentsjavascript

Throughout the course of programming, you will end up with some comments that explain code and some comments that are removing code:

// A concise description 
const a = Boolean(obj);
//b = false;

Is there a good method to quickly parse which is which?

I've played around with using 3 /'s and /** */ for descriptive comments.

I've also used a VSCode plugin to highlight //TODO: and //FIXME:

Best Answer

There is a very simple solution to this: remove the commented-out code.

Really, there are only two good reasons to comment out code: to test something/make a fix, or to save code you might use later. If you're testing or fixing something, remove the commented out code as soon as you're done with the test or fix. If you're saving code you might use later, make it first-class code and put it somewhere such as a library where it can be put to good use.

Related Topic