# Javascript

> 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).

- Skill: `pedronauck/javascript` (Agent Skill)
- Install (CLI): `npx skillmds@latest add pedronauck/javascript`
- Raw SKILL.md: https://api.skillmd.com/api/skills/pedronauck/javascript/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: pedronauck (https://skillmd.com/u/pedronauck)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/pedronauck/javascript

---


# 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`:

```ts
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.

```ts
import express from 'express';
import type { Request, Response } from 'express';
import { getHealth } from './services/healthService';

export const app = express();
```

### Typed values

Type every value with an explicit type, interface, or union, or a safe inference — leave no `any` (explicit, inferred, or via unchecked casts). For untrusted external data, take `unknown` and narrow before use. Reach for a shared contract type before an unchecked `as` cast.

```ts
function isUser(value: unknown): value is User {
  if (typeof value !== 'object' || value === null) return false;
  return 'id' in value && 'name' in value;
}
```

## Reference — review gate

Before finishing a JS/TS change, confirm: `const`/`let` only, `async`/`await` for async flow, ESM imports in Node, no `any`, and every `unknown` narrowed before use.

