Javascript Best Practices
ASecurityA small, idiomatic starting point is a pure named-exported function with validation, a named constant, and a JSDoc comment: ```js const MAX_NAME_LENGTH = 80; /** * Normalizes a display name so callers receive one predictable representation. * @param {string} value * @returns {string} */ export function normalizeName(value) { if (typeof value !== 'string') { throw new Error('name must be a string'); } const name = value.trim(); if (name.length === 0 || name.length > MAX_NAME_LENGTH) { throw ne...
- 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-4ca2d598)A small, idiomatic starting point is a pure named-exported function with validation, a named constant, and a JSDoc comment:
```js
const MAX_NAME_LENGTH = 80;
/**
* Normalizes a display name so callers receive one predictable representation.
* @param {string} value
* @returns {string}
*/
export function normalizeName(value) {
if (typeof value !== 'string') {
throw new Error('name must be a string');
}
const name = value.trim();
if (name.length === 0 || name.length > MAX_NAME_LENGTH) {
throw new Error('name has an invalid length');
}
return name;
}
```
Naming: use `camelCase` for functions and variables, `PascalCase` for classes, and `UPPER_SNAKE` for constants. Keep this entity in its own file and re-export it by name from `index.js`; avoid global state, magic numbers, deep nesting, default exports, and hidden side effects.
Comments: add JSDoc to public APIs and explain why a non-obvious rule exists, rather than repeating what the code already says. Handle async failures explicitly when the example grows to call external services.
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.