JavaScript Cheat Sheet
A quick reference for modern JavaScript syntax, methods, and patterns.
Data Types & Variables
| Primitives | string, number, boolean, null, undefined, symbol, bigint |
| typeof | typeof 'hello' → 'string'; typeof 42 → 'number' |
| let | let x = 10 (block-scoped, can reassign) |
| const | const x = 10 (block-scoped, cannot reassign) |
| var | var x = 10 (function-scoped, avoid in modern code) |
Array Methods
| map | arr.map(x => x * 2) — transform each element |
| filter | arr.filter(x => x > 5) — keep matching elements |
| reduce | arr.reduce((sum, x) => sum + x, 0) — accumulate values |
| find | arr.find(x => x.id === 3) — first match |
| some/every | arr.some(x => x > 5) / arr.every(x => x > 0) |
| includes | arr.includes(5) — check existence |
| flatMap | arr.flatMap(x => [x, x * 2]) — map then flatten |
Async Patterns
| Promise | const p = new Promise((resolve, reject) => { ... }) |
| async/await | const data = await fetch(url) |
| Promise.all | const [a, b] = await Promise.all([p1, p2]) |
| Promise.allSettled | Resolves when all settle (resolve or reject) |
| try/catch | try { await fn() } catch (err) { ... } |
| Error handling | Wrap async calls in try/catch or .catch() |