Clear Naming
One of the easiest ways to make code more readable is clear naming. Make using variables and functions as obvious as possible. Even on a one-man project, it's easy to come back to your own code after 6 months and have trouble remembering what every function does. When you're reading someone else's code, this is doubly true.
Make sure your names are clear and pronounceable. Consider the following example, where a developer has created a function that returns the date in yymm
format:
function yymm() { let date = new Date(); Return date.getFullYear() + "/" + date.getMonth(); }
When we're given the context and explanation of what this function does, it's obvious. But for an outside developer skimming over the code for the first time, yymm
can easily cause some confusion.
Vague functions should be renamed in a way that makes their use obvious:
function getYearAndMonth() { let date = new Date(); return date.getFullYear...