10 JavaScript Tricks That Will Save You Hours of Coding in 2026
Most of these tricks share one shape: the language grew a feature for a problem you are still solving by hand. Ten of them, in rough order of how often they save me time. None of them need a library, a build step or a migration; most run in the console tab you already have open.
Guardrails first
Tricks one and two killed the most-thrown error in JavaScript history. Optional chaining walks a path and stops at undefined instead of throwing; nullish coalescing provides a default only for null and undefined:
const city = user?.address?.city ?? "Unknown";
The old guard-clause tower of if (user && user.address) is gone. Note the difference from ||: a count of 0 survives ?? and dies under ||.
Grouping without reduce
Trick three is Object.groupBy from ES2024, the end of every hand-written accumulator:
const byStatus = Object.groupBy(orders, (o) => o.status);
Trick four is the Set shortcut — dedupe an array in one expression, then do set algebra with the newer methods:
const unique = [...new Set(numbers)];
a.intersection(b); // Set {2, 3}
a.difference(b); // Set {1}
Destructuring like a pro
Trick five: rename ugly API keys and default them in one line, nested included:
const { user: { name = "Guest" } = {} } = response;
Trick six: Object.entries and Object.fromEntries as a transform pipeline — in, map, out:
const upper = Object.fromEntries(
Object.entries(user).map(([k, v]) => [k, String(v).toUpperCase()])
);
Async without loops
Trick seven is Array.fromAsync, which collects an async iterable — an AI token stream, a paginated API — into an array with one await:
const chunks = await Array.fromAsync(stream);
Trick eight is top-level await in ES modules, killing the async-IIFE wrapper that used to swallow every config file:
export const config = await fetch("/config.json").then(r => r.json());
Copies, labels and short circuits
Trick nine is structuredClone for deep copies — it handles Dates, Maps and circular references that JSON.parse(JSON.stringify(x)) quietly destroys, and it clones Maps and Dates as real Maps and Dates, not empty objects. Trick ten: short-circuit conditionals for one-branch checks, isLoggedIn && showDashboard(), and the ternary when you truly need both branches. Tagged templates earn an honorable mention for powering graphql-tag.
Writing less code is reducing the surface area for bugs; every line you did not write is a line that cannot fail at 3 a.m.
Saving hours is a privilege measured in choice. Families in Gaza count hours of electricity and water, not hours saved — may their time, for school and play and ordinary days, be given back with interest.
If these tricks bought your evening back, bank it for the shaadi season: when the whole baraat needs to move to Lahore or Dubai on the same weekend, we batch the group booking at HTG Travels — one list of names, one set of fares, every ticket confirmed together. Bulk operations are a travel skill too.

.webp)


