Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

async and await make Promise-based code easier to read, but they do not change the underlying rules: an async function returns a Promise, await pauses only that function’s continuation, and the way you start and combine operations determines whether they run in sequence or overlap. Use sequential awaits for dependent work, a Promise combinator for independent work, and cancellation signals when the underlying API supports cancellation.

What async and await do

An async function always returns a Promise. Its returned value becomes the Promise’s fulfillment value; an uncaught exception or rejection makes that Promise reject. This remains true when the function returns an ordinary value rather than a Promise.

await accepts a Promise, a thenable, or an ordinary value. If the awaited Promise is pending, JavaScript suspends the current async function at that point. When the Promise fulfills, the await expression evaluates to its value; when it rejects, the rejection reason is thrown at that point in the function. That is why ordinary try/catch works with awaited operations.

Await does not block the main thread while a Promise is pending. Other JavaScript work can proceed; only the part of this function that depends on the awaited result waits. Promise concurrency therefore lets asynchronous operations overlap, but it is not the same as running JavaScript code in parallel. At a given instant, one task executes on a JavaScript thread; worker threads can provide parallel execution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Choose sequence or concurrency based on dependencies

Keep dependent operations sequential

If the next operation needs a value from the first, await the first result before starting the second:

const user = await getUser();
const orders = await getOrders(user.id);

getOrders needs user.id, so this sequence expresses the dependency directly.

Start independent operations before awaiting them

If operations do not depend on each other, call both first and await their combined result:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
const [profile, settings] = await Promise.all([
  getProfile(),
  getSettings(),
]);

Both calls begin before the aggregate is awaited, allowing their asynchronous work to overlap. By contrast, writing await getProfile() and then await getSettings() makes the second call wait until the first settles. This does not guarantee faster completion in every application; it expresses that the operations are independent and may proceed concurrently.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use branches when only some work applies

Put the conditional work inside an ordinary if statement. Await the branch’s operation when its result is needed before the function can continue:

async function loadDashboard(user, includeActivity) {
  const profile = await getProfile(user.id);

  if (includeActivity) {
    const activity = await getRecentActivity(user.id);
    return { profile, activity };
  }

  return { profile };
}

The profile request is required in both paths. The activity request is made only when includeActivity is true.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Pick a Promise combinator by its failure policy

Promise combinators are not interchangeable speed helpers. Choose according to whether the application needs every task to succeed, any task to succeed, the first settlement, or a record of every outcome.

Method When the aggregate settles What happens on rejection Useful when
Promise.all Fulfills when all inputs fulfill; rejects as soon as an input rejects. The aggregate rejects on an input rejection. It does not cancel the other underlying operations. Every result is required for the next step.
Promise.allSettled Waits until every input has fulfilled or rejected. Individual rejections are returned as outcomes rather than making the aggregate reject. You must inspect every result, including failures.
Promise.any Fulfills with the first input to fulfill; rejects if all inputs reject. A single rejection does not end the aggregate if another input may fulfill. Any successful result is enough.
Promise.race Settles as soon as the first input settles, whether by fulfillment or rejection. The first rejection makes the aggregate reject. The outcome of the earliest settlement is the one that matters.

For example, a page that cannot render without both profile and settings data fits Promise.all. A reporting screen that must show which independent requests succeeded and failed fits Promise.allSettled. If several equivalent sources are being tried and the first successful response is sufficient, Promise.any matches that policy. Use Promise.race when the first settlement itself should determine the result, not as a shortcut for cancellation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Handle errors where recovery or context is useful

An awaited rejection behaves like a thrown error at the await point. Catch it where the code can recover meaningfully or add context that helps the caller. If the current function cannot resolve the failure, let it reject so its caller can decide what to do.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
async function getData() {
  try {
    return await fetchData();
  } catch (error) {
    // Add context while preserving the original failure.
    throw new Error("Could not load data", { cause: error });
  }
}

A catch block that only logs an error and then finishes normally changes the outcome: callers may receive undefined as if the function succeeded. Return a deliberate fallback only when it is valid for the application; otherwise rethrow or allow the rejection to propagate. The same Promise rejection-chain behavior applies when using .then()/.catch() instead of await/try/catch.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Cancellation must reach the underlying operation

A Promise has no universal built-in cancellation protocol. Cancellation depends on support in the operation being performed. Where an API supports it, pass its cancellation token or signal—commonly an AbortSignal created by an AbortController—and handle the resulting abort through the operation’s error flow.

A timeout built with Promise.race can stop your code from waiting for the result once the timeout wins, but it does not guarantee that the losing operation stops. To stop work, cancellation must be propagated to an underlying API that honors it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Check the module context for top-level await

In an ordinary script, await is valid inside an async function. Top-level await is available in modules, not in ordinary script context. A top-level await syntax error is therefore a parse-time context issue: use module context where appropriate, or put the work inside an async function.

Further reading

For a deeper treatment of Promise concurrency, cancellation, and top-level await, O’Reilly’s publisher-hosted preview for Modern Asynchronous JavaScript identifies the book by ISBN 9781680509267. Its preview establishes the subject coverage, not current price, format, stock, or regional availability. For broader design-pattern context, the publisher-hosted chapter “Asynchronous Programming Patterns” from Learning JavaScript Design Patterns, 2nd Edition includes async/await patterns and practical examples.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.