Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

JavaScript (ES2026) Module 13

Asynchronous JavaScript interview questions

Interview questions on asynchronous JavaScript: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

7 questions: 2 warm-ups and 5 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    JavaScript is single-threaded. How can a page still load data, run timers and react to clicks at the same time?

    Answered in the lesson Synchronous and asynchronous code

  2. Fresher

    What is an error-first callback, and which rules does a function that takes one follow?

    Answered in the lesson Callbacks and error-first style

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    An Export button builds a large CSV file in one loop. During the six-second export the page ignores clicks, and the progress bar that the loop updates every 1,000 rows never moves until it jumps to 100 %. Explain what is happening, and give two fixes with what each one costs.

    What it tests
    Run-to-completion, why the browser cannot repaint during a task, splitting work into chunks, moving it to a Web Worker, and the costs of each fix.
    First step
    Notice that the progress updates do happen: the loop changes the bar every 1,000 rows. But the browser updates the rendering only between tasks, and the whole export is one task of six seconds, so no repaint, click or timer can happen until it ends, and the bar is painted only once, at 100 %.
    Follow-ups

    From the lesson Synchronous and asynchronous code

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    A Node.js login endpoint hashes passwords with a synchronous function that takes 80 ms. At 50 logins a second, every endpoint, even /health, slows to several seconds and keeps getting slower. Explain the mechanism with numbers, and fix it.

    What it tests
    The single event-loop thread, capacity arithmetic, the worker pool behind Node's asynchronous crypto functions, and keeping cheap endpoints fast while expensive ones are busy.
    First step
    Do the arithmetic first. 50 logins a second at 80 ms each is 4 seconds of hashing every second, on one thread that has 1 second per second. Work arrives four times faster than it can be done, so the queue of waiting requests grows without limit, and /health waits in the same queue.
    Follow-ups

    From the lesson Synchronous and asynchronous code

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    A payment client gives up after 5 seconds and calls back with a timeout error, but when the bank's answer arrives later it calls the same callback again. Some customers see "Payment failed", pay again, and are charged twice. Explain the bug and fix it at every level it touches.

    What it tests
    Callbacks that run more than once, cancelling timers, a once() guard, and why a timeout does not mean the operation failed: payment status checks and idempotency keys.
    First step
    Separate the two bugs. The client calls back twice because nothing cancels the timeout when the answer comes, and nothing ignores an answer that comes after the timeout. And a timeout only means the client stopped waiting: the bank may still charge the card, so "failed" is the wrong thing to tell the customer.
    Follow-ups

    From the lesson Callbacks and error-first style

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Fresher to mid

    A Node.js service wraps fs.readFile(path, callback) in try…catch, yet a JSON.parse() error inside the callback crashes the whole process and drops every request in flight. Explain why the catch never runs, and how you would structure error handling in a callback-based module so that one bad file cannot stop the server.

    What it tests
    Why a callback's throw escapes the caller's try…catch, error-first propagation, uncaughtException as a last resort, and containing a failure to one request.
    First step
    Look at when the callback runs. readFile() returns at once, and the try block ends with it. The callback runs later, from the event loop, with no frame of the caller left on the stack, so its throw becomes an uncaught exception, and Node.js prints it and exits with code 1.
    Follow-ups

    From the lesson Callbacks and error-first style

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Mid to senior

    Without promises, a page needs a profile, orders and recommendations from three independent callback APIs, fetched in parallel and delivered to one callback. Describe how you keep the results in order, and what happens when one call fails, when two fail, and when one never answers.

    What it tests
    Running callbacks in parallel with a counter, keeping input order, calling back exactly once, optional parts and timeouts.
    First step
    Start all three calls at once and count the answers. Store each result at its position in an array, so the input order survives whatever order the answers arrive in, and keep a finished flag, so the final callback runs exactly once: after the third success or the first error.
    Follow-ups

    From the lesson Callbacks and error-first style

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All JavaScript (ES2026) interview questions · The JavaScript (ES2026) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.