JavaScript ES6+ Cheatsheet
Modern JavaScript — arrow functions, destructuring, promises, modules, and ES2024 features.
JavaScript has evolved rapidly from ES6 (2015) onward. This cheatsheet covers the modern syntax and patterns you will actually use: arrow functions, template literals, destructuring, spread/rest, Promises, async/await, ES modules, and newer additions like optional chaining and nullish coalescing.
All examples target Node.js 20+ or modern browsers.
Variables & Scoping
const x = 42let x = 42Functions
() => { ... }arr.map(x => x * 2)arr.filter(x => x > 0)arr.reduce((acc, x) => acc + x, 0)Objects & Arrays
const { name, age } = objconst [first, ...rest] = arrconst merged = { ...obj1, ...obj2 }Promises & Async
new Promise((resolve, reject) => { ... })async function fetchData() { ... }await promisePromise.all([p1, p2])Modules & Imports
import { name } from "./module"export default function() {}export const NAME = "value"Modern Syntax
obj?.propval ?? "default"const url = `https://${host}/api/${id}`arr.flatMap(x => [x, x * 2])JavaScript ES6+ Cheatsheet
Modern JavaScript — arrow functions, destructuring, promises, modules, and ES2024 features.
JavaScript has evolved rapidly from ES6 (2015) onward. This cheatsheet covers the modern syntax and patterns you will actually use: arrow functions, template literals, destructuring, spread/rest, Promises, async/await, ES modules, and newer additions like optional chaining and nullish coalescing.
All examples target Node.js 20+ or modern browsers.
Variables & Scoping
const x = 42 — Block-scoped constant. Cannot be reassigned (but object contents can change).let x = 42 — Block-scoped variable that can be reassigned.Functions
() => { ... } — Arrow function — inherits this from enclosing scope. No arguments object.arr.map(x => x * 2) — Creates a new array by transforming each element.arr.filter(x => x > 0) — Creates a new array with elements that pass the test.arr.reduce((acc, x) => acc + x, 0) — Reduces array to a single value by accumulating.Objects & Arrays
const { name, age } = obj — Object destructuring — extract properties into variables.const [first, ...rest] = arr — Array destructuring with rest element.const merged = { ...obj1, ...obj2 } — Spread operator — shallow-merge objects or clone arrays.Promises & Async
new Promise((resolve, reject) => { ... }) — Create a promise for async operations. Resolve on success, reject on error.async function fetchData() { ... } — Declare an async function that returns a Promise.await promise — Pause execution until a Promise resolves. Can only be used inside async functions.Promise.all([p1, p2]) — Wait for all promises to resolve. Rejects if any rejects.Modules & Imports
import { name } from "./module" — Import named exports from an ES module.export default function() {} — Default export — one per module. Import without curly braces.export const NAME = "value" — Named export — can import selectively with destructuring.Modern Syntax
obj?.prop — Optional chaining — safely access nested properties without checking each level.val ?? "default" — Nullish coalescing — returns default only if val is null or undefined.const url = `https://${host}/api/${id}` — Template literal — embed expressions in strings with ${}.arr.flatMap(x => [x, x * 2]) — Map each element then flatten the result by one level.