Javascript Best Practices
ASecurityFor a maintainable JavaScript implementation: - Use `camelCase` for variables and functions, `PascalCase` for classes, and `UPPER_SNAKE` for constants. - Keep one main entity per file. Put the public named exports in `index.js`, and order imports as external packages, internal modules, then relative modules. - Throw `Error` objects rather than strings, and handle rejected promises at the boundary that can recover or report them. - Add JSDoc to public APIs, explaining the reason for non-obviou...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 12 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill javascript-best-practices --agent claude-codeAre you the author of Javascript Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-javascript-best-practices-agent-skills-standard)For a maintainable JavaScript implementation:
- Use `camelCase` for variables and functions, `PascalCase` for classes, and `UPPER_SNAKE` for constants.
- Keep one main entity per file. Put the public named exports in `index.js`, and order imports as external packages, internal modules, then relative modules.
- Throw `Error` objects rather than strings, and handle rejected promises at the boundary that can recover or report them.
- Add JSDoc to public APIs, explaining the reason for non-obvious decisions.
- Encapsulate mutable state, replace magic numbers with named `const` values, and use guard clauses to avoid deep nesting. Prefer pure functions with no hidden side effects.
Example:
```js
const MAX_RETRIES = 3;
/**
* Retries an operation so transient failures do not fail the request immediately.
* @param {() => Promise<unknown>} operation
* @returns {Promise<unknown>}
*/
export async function retry(operation) {
if (typeof operation !== 'function') {
throw new Error('operation must be a function');
}
for (let attempt = 0; attempt < MAX_RETRIES; attempt += 1) {
try {
return await operation();
} catch (error) {
if (attempt === MAX_RETRIES - 1) {
throw error instanceof Error ? error : new Error(String(error));
}
}
}
}
```
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.