Errors & Good Practice›Extra· 25 min read
JavaScript Best Practices
Habits that make your code clean, readable and professional.
What you will learn
- Follow naming and structure conventions
- Avoid common pitfalls
- Write code others can read
The professional checklist
- Use
constby default,letwhen needed, nevervar. - Use
===, never==. - Use camelCase and descriptive names.
- Keep functions small and focused on one job.
- Indent consistently and end statements with
;. - Prefer
map/filter/reduceover manual loops when it reads clearer. - Handle errors; do not ignore them.
- Comment the why, not the obvious what.
Tip: Install a linter (ESLint) and a formatter (Prettier) in VS Code. They catch mistakes and auto-format your code — instant professionalism, used on every real team.
Q. Which is the best modern default for declaring variables?
Answer: Prefer const by default; use let only when the value must change. Avoid var in modern code.
✍️ Practice
- Review an old script and improve it against the checklist.
- Set up Prettier in VS Code and format a file.
🏠 Homework
- Write your own 6-point JavaScript style checklist.