package.json, module system, Node version, browser targets; confirm .js/.mjs/.cjs conventionseslint --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 continuingLoad 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 |
X | null or X | undefined patterns?.) and nullish coalescing (??)import/export) for new projectsvar (always use const or let)// ✅ 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();
}
// ✅ Correct
const city = user?.address?.city ?? "Unknown";
// ❌ Incorrect — throws if address is undefined
const city = user.address.city || "Unknown";
// ✅ 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");
// ✅ Correct
const MAX_RETRIES = 3;
let attempts = 0;
// ❌ Incorrect
var MAX_RETRIES = 3;
var attempts = 0;
When implementing JavaScript features, provide: