What are the best practices for writing clean JavaScript?
Clean JavaScript is readable, predictable, and easy to change. Core habits:
Clear names — descriptive variables and functions; avoid cryptic abbreviations.
Small functions — each does one thing.
const by default — prefer immutability; avoid var.
Avoid side effects — favour pure functions where practical.
Handle errors — don't swallow them; fail clearly.
Consistent style — use a linter and formatter (ESLint, Prettier).
Guiding idea: write code for the next person to read, not just for the machine to run.
Organize by category: naming, functions, modern syntax, async, organization. Mention specific tools: ESLint (linting), Prettier (formatting), and specific rules (const by default, === over ==).
These conventions are expected in professional JavaScript code.