| name | javascript |
| description | JavaScript and TypeScript language patterns — const/let, async/await, ESM imports, and typed unknowns. Use when writing or reviewing JS/TS in frontend or backend. Don't use for React component patterns (use react), general file-size or nesting standards (use code-standards), or test structure (use tests). |
JavaScript and TypeScript
Apply these language patterns to frontend and backend JS/TS. For file size, nesting, and related shape rules, invoke code-standards in full. For React components and hooks, invoke react in full.
Reference — language rules
const by default
Declare with const whenever the binding is not reassigned. Use let only when reassignment is required. Mutating an object's contents does not require let — the binding stays const.
async/await
Drive async flow with async/await and explicit try/catch when errors must be handled. For independent work, combine with Promise.all:
const [user, settings] = await Promise.all([
loadUser(userId),
loadSettings(userId),
]);
ESM in Node
In backend Node code, use import/export. Use import type for type-only imports.
import express ;
{ , } ;
{ getHealth } ;
app = ();