The independent file on technology, travel & lifeFrom Pakistan, for everywhere
Huzi Blogs.
The ArchiveSectionsSearch

Planning a trip? HTG Travels — flights, visas, hotels & Umrah, handled properly.

WhatsApp +92 317 5054959
Huzi Blogs.

An independent file on technology, travel and life — long-form guides written plainly, from Pakistan, for everywhere.

ShopMeet the Creator

Sections

  • Travel
  • Technology
  • Lifestyle
  • Programming
  • Sports
  • Linux
  • All sections

The Desk

  • The Archive
  • Search the file
  • Disclaimer & Data Privacy Policy
  • A project of huzi.pk

© 2026 blogs.huzi.pk — All rights reserved.

Set in Playfair Display & Inter

    HomeProgrammingStory
    Programming

    10 JavaScript Tricks That Will Save You Hours of Coding in 2026

    H

    By Huzi

    File #284 · 4 min read

    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 — and the foundations underneath them are laid out in the modern script guide.

    The quick answer: The biggest wins are ?. and ?? for safe access, Object.groupBy for grouping, and structuredClone for deep copies. Every one of the ten is native — no library, no build step — and the cheat sheet at the bottom rounds them all up.

    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());
    

    Streams that resolve into one finished result — that is also how a booking thread should end. At HTG Travels, the chatter of dates, fares and names resolves into one written itinerary, the way Array.fromAsync resolves a token stream into an array.

    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.

    The trick What it replaces Why it matters
    ?. and ?? The if (user && user.address) guard tower A count of 0 survives ??
    Object.groupBy Hand-written accumulator loops One expression, ES2024
    Set methods Dedupe and filter loops [...new Set(numbers)], then intersection and difference
    Array.fromAsync The awaited for-loop One await collects an async iterable
    Top-level await The async-IIFE wrapper Config files read like code again
    structuredClone JSON.parse(JSON.stringify(x)) Dates, Maps and circular references survive

    Pro tip: 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.

    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. Sudan's families count the same hours, and the months since displacement — may their time be repaid the same way, with homes and ordinary mornings.

    If these tricks bought your evening back, bank it for the shaadi season: when the whole baraat must move to Lahore or Dubai on one weekend, we batch the group booking at HTG Travels — one list of names, one set of fares, every ticket confirmed together. Reach the desk on +92 317 5054959 when the backlog clears.

    Presented by

    HTG Travels — Plan the Trip, Skip the Runaround

    Flights, visas, Umrah packages and Hunza–Skardu tours, handled end to end from our licensed Sialkot desk. Real fares, hotel names in writing, and a human who answers — before you pay a rupee.

    Flights & rebooking Visa files Umrah 2026–27 Northern tours
    Visit huzi.pkWhatsApp +92 317 5054959

    Sialkot, Pakistan · Licensed agency · Fast quotes on WhatsApp


    You Might Also Like

    Glamorous Handwork Heavy Embroidered Black Velvet Suit 2026 (5000 Micro Velvet)

    Glamorous Handwork Heavy Embroidered Black Velvet Suit 2026 (5000 Micro Velvet)

    PKR 7550

    Adorable Embroidered Black Velvet Dress 2026 with Net Dupatta

    Adorable Embroidered Black Velvet Dress 2026 with Net Dupatta

    PKR 6350

    Powder Blue Embroidered NET Bridal Maxi Dress – 12 Kali Lehenga with Rich Embellishments

    Powder Blue Embroidered NET Bridal Maxi Dress – 12 Kali Lehenga with Rich Embellishments

    PKR 14000

    Fashion Men’s Unstitched Shalwar Kameez – Premium Soft Egyptian Cotton Fabric | Summer Wear Pakistan

    Fashion Men’s Unstitched Shalwar Kameez – Premium Soft Egyptian Cotton Fabric | Summer Wear Pakistan

    PKR 3000

    Teal Blue Sequins Embroidered Chiffon Party & Wedding Dress – Unstitched Luxury Outfit

    Teal Blue Sequins Embroidered Chiffon Party & Wedding Dress – Unstitched Luxury Outfit

    PKR 5500

    Keep reading

    Related files

    Programming
    English

    The Modern Script: Top 5 ES2024+ Features You Must Use in 2026

    From let and const to arrow functions, destructuring, spread and template literals, plus the ES2024 arrivals — Object.groupBy, Set algebra and top-level await.

    By HuziFile #283

    Read
    Programming
    English

    Beyond the Wait: Master Async/Await in JavaScript (2026)

    The modern async toolkit: try/catch around await, Promise.all for parallel work, the forEach trap, AbortController for cancellation, and async iterators for streams.

    By HuziFile #119

    Read
    Programming
    English

    Modern Styling: Advanced CSS Techniques for 2026

    Container queries, the :has() parent selector, typed custom properties with @property, and scroll-driven animations — the modern CSS that ships in every evergreen browser today.

    By HuziFile #13

    Read
    Programming
    English

    Rust for JavaScript Developers 2026: The Complete Problem-Solving Guide

    Ownership, borrowing, Option, Result and the ? operator, Tokio and a first Axum API — Rust explained through the JavaScript habits you already have.

    By HuziFile #538

    Read
    Programming
    English

    The Developer's Toolkit: Top 10 VS Code Extensions for 2026

    Ten VS Code extensions that earn their keep in 2026, from Copilot and Cursor to Prettier, ESLint, GitLens and Thunder Client, plus the settings that wire them together.

    By HuziFile #435

    Read
    Programming
    English

    The Static Renaissance: Why Pre-Rendered Webs are Winning in 2026

    Build-time rendering, CDN edges, on-demand revalidation and Astro Server Islands — why static-first is the 2026 default for fast, secure, cheap sites.

    By HuziFile #417

    Read
    Back to the archive