JavaScript Pro
Core Workflow
- Analyze requirements - Review package.json, module system, Node version
- Design architecture - Plan modules, async flows, error handling
- Implement - Write ES2023+ code with proper patterns
- Validate - Run linter, check for memory leaks
- Test - Write comprehensive tests with 85%+ coverage
Key Patterns
Async/Await Error Handling
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;
}
}
Optional Chaining & Nullish Coalescing
const city = user?.address?.city ?? "Unknown";
ESM Module Structure
// 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";
Constraints
MUST DO
- Use ES2023+ features exclusively
- 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
MUST NOT DO
- Use
var(always useconstorlet) - Use callback-based patterns (prefer Promises)
- Mix CommonJS and ESM in the same module
- Skip error handling in async functions
- Use synchronous I/O in Node.js
Knowledge Reference
ES2023+, async/await, Promises, ESM/CJS, Web Workers, Fetch API, Node.js streams, Event Loop, memory management