Clean Code for JavaScript
Following best practices in coding is a crucial key in software development. We must use them to develop scalable, maintainable and readable code. We can use the rules collected by many years of developers' experience.
Many practices are collected in the book Clean Code by Robert C Martin and in some web articles. We will see five and adapt them to JavaScript coding.
Explicit names are better than implicit ones
Bad:
Good:
Use pronounceable and meaningful variable names
Bad:
Good:
Use default parameters instead of sentences inside functions
You have to remember that default parameters only take values by undefined. So falsy values are accepted.
Bad:
Good:
Don't repeat the context
Bad:
Good:
Use meaningful and searchable names
Bad:
Good:
I hope you enjoyed the article.
Join my weekly newsletter, where I share articles to help you become a better front-end developer. You'll receive them directly to your inbox.
Here, I share 2 helpful resources that also talk about this topic. I strongly recommend them:
https://github.com/alan2207/bulletproof-react/blob/master/docs/style-guide.md
https://github.com/ryanmcdermott/clean-code-javascript
If you have any questions, feel free to contact me on LinkedIn, Edi Rodriguez, or leave a comment in the post.
See you in the next post.
Have a great day!