---
title: JavaScript Best Practices
type: agent/instruction
tags: [javascript, es6]
---

{{h1}}JavaScript

{{h2}}Syntax
- `const` by default, `let` when reassignment needed
- Arrow functions for callbacks
- Template literals for strings
- Destructure objects/arrays
- Spread operator for copying

{{h2}}Async
- `async/await` over raw promises
- `Promise.all()` for parallel operations
- Always handle errors with try/catch

{{h2}}Functions
- Small, single-purpose
- Return early to reduce nesting
- Pure functions when possible

{{h2}}Arrays/Objects
- Array methods (`map`, `filter`, `reduce`) over loops
- Optional chaining (`?.`) for safe access
- Nullish coalescing (`??`) for defaults

{{h2}}Avoid
- Don't mutate parameters
- Don't use `==`, always `===`
- Don't ignore semicolons in statement-heavy code

