Good names reduce the amount of code a reader must hold in their head. They describe the thing as it is used, not as it happened to be implemented.
Prefer intention
Compare:
const x = posts.filter((item) => !item.data.draft);
const publishedPosts = posts.filter((post) => !post.data.draft);
The second version does not need a comment. It gives the reader a useful assumption immediately.
Names should survive change
Names based on temporary details age badly:
newPostsbecomes confusing after a refresh;blueButtonbreaks when the design changes;datasays nothing about its shape;handleIthides the action.
| Weak | Clearer |
|---|---|
data |
articleMetadata |
run |
generatePreview |
list |
publishedArticles |
tmp |
normalizedSlug |
Naming is a small design task performed inside the code. Give it the same care you give labels in the interface.