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.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
JavaScript is single-threaded. How can a page still load data, run timers and react to clicks at the same time?
-
Fresher
What is an error-first callback, and which rules does a function that takes one follow?
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
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
-
- How big should each chunk be?
- When is a Web Worker the better fix?
- Why does marking the export function async not help?
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.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
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
-
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
-
- Why does the asynchronous crypto.scrypt() help, and where is its limit?
- Would running more Node.js processes fix it?
- How would you have caught this before production?
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
-
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
-
- Is a once() wrapper enough on its own?
- What should the customer see after a timeout?
- How do you stop the second payment from charging the card again?
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
-
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
-
- Why not add a process.on('uncaughtException') handler and keep running?
- Where exactly does the try…catch belong?
- What changes with fs.promises and await?
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
-
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
-
- Recommendations are optional. What changes?
- How do you deal with an API that never calls back?
- The calls take 120, 80 and 300 ms. How long does the page wait, in sequence and in parallel?
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