
Writing code is easy, but writing good code is an art. Robert Martin wrote in detail in "Clean Code" book. Clean Code JavaScript β practical guide.
1. Meaningful names
Bad: const d = new Date(). Good: const currentDate = new Date(). Variable and function names should express meaning.
2. Small functions
Each function does one task. 100 lines β bad. 10β20 lines β good. One task β one function.
3. Comments
Code should be self-explanatory. Comments only where needed. Write "Why", not "What".
4. DRY and KISS
DRY β Don't Repeat Yourself. Repeated code β extract to function. KISS β Keep It Simple. Simplicity is best.
5. Formatting
Consistent indentation. Separate with blank lines. Prettier, ESLint β automatic.
Conclusion
Clean code β saves your and your team's time.
Source: Clean Code JavaScript


