JavaScript Pro
When to Use This Skill
- Building vanilla JavaScript applications
- Implementing async/await patterns and Promise handling
- Working with modern module systems (ESM/CJS)
- Optimizing browser performance and memory usage
- Developing Node.js backend services
- Implementing Web Workers, Service Workers, or browser APIs
Core Workflow
- Analyze requirements — Review
package.json, module system, Node version, browser targets; confirm .js/.mjs/.cjs conventions
- Design architecture — Plan modules, async flows, and error handling strategies
- Implement — Write ES2023+ code with proper patterns and optimisations
- Validate — Run linter (
eslint --fix); if linter fails, fix all reported issues and re-run before proceeding. Check for memory leaks with DevTools or --inspect, verify bundle size; if leaks are found, resolve them before continuing
- Test — Write comprehensive tests with Jest achieving 85%+ coverage; if coverage falls short, add missing cases and re-run. Confirm no unhandled Promise rejections
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Modern Syntax |
references/modern-syntax.md |
ES2023+ features, optional chaining, private fields |
| Async Patterns |
references/async-patterns.md |
Promises, async/await, error handling, event loop |
| Modules |
references/modules.md |
ESM vs CJS, dynamic imports, package.json exports |
| Browser APIs |
references/browser-apis.md |
Fetch, Web Workers, Storage, IntersectionObserver |
| Node Essentials |
references/node-essentials.md |
fs/promises, streams, EventEmitter, worker threads |
Constraints
MUST DO
- Use ES2023+ features exclusively
- Use
X | null or X | undefined patterns
- Use optional chaining (
?.) and nullish coalescing (??)
- Use async/await for all asynchronous operations
- Use ESM (
import/export) for new projects
- Implement proper error handling with try/catch
- Add JSDoc comments for complex functions
- Follow functional programming principles
MUST NOT DO
- Use
var (always use const or let)
- Use callback-based patterns (prefer Promises)
- Mix CommonJS and ESM in the same module
- Ignore memory leaks or performance issues
- Skip error handling in async functions
- Use synchronous I/O in Node.js
- Mutate function parameters
- Create blocking operations in the browser
Key Patterns with Examples
Async/Await Error Handling
// ✅ Correct — always handle async errors explicitly
async function fetchUser(id) {
try {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return await response.json();
} catch (err) {
console.error("fetchUser failed:", err);
return null;
}
}
// ❌ Incorrect — unhandled rejection, no null guard
async function fetchUser(id) {
const response = await fetch(`/api/users/${id}`);
return response.json();
}
Optional Chaining & Nullish Coalescing
// ✅ Correct
const city = user?.address?.city ?? "Unknown";
// ❌ Incorrect — throws if address is undefined
const city = user.address.city || "Unknown";
ESM Module Structure
// ✅ Correct — named exports, no default-only exports for libraries
// utils/math.mjs
export const add = (a, b) => a + b;
export const multiply = (a, b) => a * b;
// consumer.mjs
import { add } from "./utils/math.mjs";
// ❌ Incorrect — mixing require() with ESM
const { add } = require("./utils/math.mjs");
Avoid var / Prefer const
// ✅ Correct
const MAX_RETRIES = 3;
let attempts = 0;
// ❌ Incorrect
var MAX_RETRIES = 3;
var attempts = 0;
Output Templates
When implementing JavaScript features, provide:
- Module file with clean exports
- Test file with comprehensive coverage
- JSDoc documentation for public APIs
- Brief explanation of patterns used
1---2name: javascript-pro3description: Writes, debugs, and refactors JavaScript code using modern ES2023+ features, async/await patterns, ESM module systems, and Node.js APIs. Use when building vanilla JavaScript applications, implementing Promise-based async flows, optimising browser or Node.js performance, working with Web Workers or Fetch API, or reviewing .js/.mjs/.cjs files for correctness and best practices.4license: MIT5---67# JavaScript Pro89## When to Use This Skill1011- Building vanilla JavaScript applications12- Implementing async/await patterns and Promise handling13- Working with modern module systems (ESM/CJS)14- Optimizing browser performance and memory usage15- Developing Node.js backend services16- Implementing Web Workers, Service Workers, or browser APIs1718## Core Workflow19201. **Analyze requirements** — Review `package.json`, module system, Node version, browser targets; confirm `.js`/`.mjs`/`.cjs` conventions212. **Design architecture** — Plan modules, async flows, and error handling strategies223. **Implement** — Write ES2023+ code with proper patterns and optimisations234. **Validate** — Run linter (`eslint --fix`); if linter fails, fix all reported issues and re-run before proceeding. Check for memory leaks with DevTools or `--inspect`, verify bundle size; if leaks are found, resolve them before continuing245. **Test** — Write comprehensive tests with Jest achieving 85%+ coverage; if coverage falls short, add missing cases and re-run. Confirm no unhandled Promise rejections2526## Reference Guide2728Load detailed guidance based on context:2930| Topic | Reference | Load When |31|-------|-----------|-----------|32| Modern Syntax | `references/modern-syntax.md` | ES2023+ features, optional chaining, private fields |33| Async Patterns | `references/async-patterns.md` | Promises, async/await, error handling, event loop |34| Modules | `references/modules.md` | ESM vs CJS, dynamic imports, package.json exports |35| Browser APIs | `references/browser-apis.md` | Fetch, Web Workers, Storage, IntersectionObserver |36| Node Essentials | `references/node-essentials.md` | fs/promises, streams, EventEmitter, worker threads |3738## Constraints3940### MUST DO41- Use ES2023+ features exclusively42- Use `X | null` or `X | undefined` patterns43- Use optional chaining (`?.`) and nullish coalescing (`??`)44- Use async/await for all asynchronous operations45- Use ESM (`import`/`export`) for new projects46- Implement proper error handling with try/catch47- Add JSDoc comments for complex functions48- Follow functional programming principles4950### MUST NOT DO51- Use `var` (always use `const` or `let`)52- Use callback-based patterns (prefer Promises)53- Mix CommonJS and ESM in the same module54- Ignore memory leaks or performance issues55- Skip error handling in async functions56- Use synchronous I/O in Node.js57- Mutate function parameters58- Create blocking operations in the browser5960## Key Patterns with Examples6162### Async/Await Error Handling63```js64// ✅ Correct — always handle async errors explicitly65async function fetchUser(id) {66 try {67 const response = await fetch(`/api/users/${id}`);68 if (!response.ok) throw new Error(`HTTP ${response.status}`);69 return await response.json();70 } catch (err) {71 console.error("fetchUser failed:", err);72 return null;73 }74}7576// ❌ Incorrect — unhandled rejection, no null guard77async function fetchUser(id) {78 const response = await fetch(`/api/users/${id}`);79 return response.json();80}81```8283### Optional Chaining & Nullish Coalescing84```js85// ✅ Correct86const city = user?.address?.city ?? "Unknown";8788// ❌ Incorrect — throws if address is undefined89const city = user.address.city || "Unknown";90```9192### ESM Module Structure93```js94// ✅ Correct — named exports, no default-only exports for libraries95// utils/math.mjs96export const add = (a, b) => a + b;97export const multiply = (a, b) => a * b;9899// consumer.mjs100import { add } from "./utils/math.mjs";101102// ❌ Incorrect — mixing require() with ESM103const { add } = require("./utils/math.mjs");104```105106### Avoid var / Prefer const107```js108// ✅ Correct109const MAX_RETRIES = 3;110let attempts = 0;111112// ❌ Incorrect113var MAX_RETRIES = 3;114var attempts = 0;115```116117## Output Templates118119When implementing JavaScript features, provide:1201. Module file with clean exports1212. Test file with comprehensive coverage1223. JSDoc documentation for public APIs1234. Brief explanation of patterns used