[{"data":1,"prerenderedAt":14},["ShallowReactive",2],{"post-small-javascript-habits-that-scale":3},{"_path":4,"title":5,"description":6,"date":7,"tags":8,"readingTime":12,"body":13},"\u002Fblog\u002Fsmall-javascript-habits-that-scale\u002F","Small JavaScript Habits That Scale","Everyday habits—naming, early returns, and clearer async flow—that keep front-end codebases maintainable.","2026-02-18",[9,10,11],"javascript","best-practices","frontend",2,"# Small JavaScript Habits That Scale\n\nBig architecture decisions matter, but day-to-day habits often decide whether a codebase stays pleasant six months later.\n\n## Name for the next reader\n\nPrefer names that say what the value *means*, not how it was computed:\n\n```javascript\n\u002F\u002F harder to scan\nconst d = posts.filter(p => p.date > cutoff);\n\n\u002F\u002F clearer\nconst recentPosts = posts.filter(post => post.date > cutoff);\n```\n\nShort names are fine for tiny scopes (`i`, `el`). Everything else should read like a sentence fragment.\n\n## Return early\n\nGuard clauses cut nesting and make the happy path obvious:\n\n```javascript\nasync function loadPost(slug) {\n  if (!slug) return null;\n\n  try {\n    return await $fetch(`\u002Fblog-posts\u002F${slug}.json`);\n  } catch {\n    return null;\n  }\n}\n```\n\nDeep `if\u002Felse` pyramids are usually a sign the function is doing too much—or refusing to exit.\n\n## Make async failure visible\n\nSwallowing errors quietly leads to “empty UI with no explanation.” Surface pending and error state to the caller, even if the UI only shows a simple message.\n\n```javascript\nconst pending = ref(false);\nconst error = ref(null);\n\nasync function run(task) {\n  pending.value = true;\n  error.value = null;\n  try {\n    return await task();\n  } catch (e) {\n    error.value = e;\n    throw e;\n  } finally {\n    pending.value = false;\n  }\n}\n```\n\n## Delete clever code\n\nA one-liner that needs a comment to explain itself usually loses to three clear lines. Optimize for the teammate (or future you) who will debug this at midnight.\n\n## Wrap-up\n\nHabits compound. Clear names, early returns, and honest async state will outlast most framework churn—and they transfer cleanly from vanilla JS to Vue, React, or whatever you pick next.",1784110285918]