Cheat sheetFree, no sign-upPDF
JavaScript ES6+ Cheat Sheet: Modern Syntax & Methods
A quick reference for modern ES6+ JavaScript features including arrow functions, destructuring, async code, and array methods.
Updated on November 10, 2026
Variables and Scope
const currency = "USD";Declares a read-only reference. Note that object properties or array items inside can still be mutated.let balance = 500;Declares a block-scoped reassignable variable. Use this over var to avoid unexpected scoping leaks.const msg = `Balance: ${balance} ${currency}`;Interpolates expressions inside template strings using backticks. Helps avoid tedious string concatenation.
Arrow Functions
const add = (a, b) => a + b;Concise function syntax. Returns value implicitly when written on one line without curly braces.const double = n => n * 2;Omit parentheses around parameters when there is exactly one argument.const getUser = () => ({ id: 1, city: "Lagos" });Wrap an object literal in parentheses to return it implicitly without opening a block.
Destructuring and Spread
const { name, city } = user;Extracts properties from an object into local variables. Yields undefined if the key does not exist.const [first, second] = list;Unpacks elements from an array into variables based on their index position.const updatedUser = { ...user, active: true };Shallow copies properties of an object while overriding or appending new attributes easily.const sumAll = (...numbers) => numbers.reduce((a, b) => a + b, 0);Rest parameters collect any remaining arguments into a clean, iterable array.
Modern Array Methods
const names = users.map(u => u.name);Transforms every array item into a new item and returns a brand new array of equal length.const paid = txs.filter(t => t.status === "SUCCESS");Creates a new array with elements passing the test. Returns an empty array if none match.const target = users.find(u => u.id === targetId);Returns the first matching element in the array, or undefined if nothing satisfies the predicate.const total = cart.reduce((acc, item) => acc + item.price, 0);Reduces an array into a single value. Always provide an initial value to prevent runtime errors.
Modern Safety Operators
const town = user?.address?.city;Optional chaining short-circuits to undefined instead of throwing errors on null or undefined.const timeout = userTimeout ?? 5000;Nullish coalescing uses fallback only when operand is null or undefined (unlike falsy || operator).const parsed = JSON.parse(jsonString);Parses a valid JSON string. You can test and format payload structures with JcHub JSON Formatter & Validator.
Async ES6+
const res = await fetch(url); const data = await res.json();Pauses execution until a promise resolves. Must be used inside an async function.const [users, posts] = await Promise.all([getUsers(), getPosts()]);Runs promises concurrently. Rejects instantly if any single promise fails.try { await processPayment(); } catch (err) { console.error(err); }Catches errors thrown during asynchronous calls inside standard try catch blocks.
Other resources
Need help with your website?
See the services I build your custom website.
Showcase site, online shop, management tool: let’s talk about your project.