Scenario-based JavaScript interview questions.

Scenario questions describe a product problem and ask what you would build: an API that fails half the time, a search box that fires too many requests, a list of uploads that must run four at a time. These are medium-level JavaScript questions drawn from real work, each with tests that check the edge cases interviewers ask about next.

7 of these questions have free answers; the rest are in Pro. Updated .

245

questions

Medium
245

What interviewers look for

  • You restate the scenario and its limits before writing code.
  • You handle failure: timeouts, retries with backoff, cancellation and partial results.
  • You keep the order of results and the number of requests under control.
  • You can explain the trade-offs of your design and what you would test.

Concept questions, answered

The definitions and comparisons interviewers open with. Free to read, each with a full answer and examples.

How should a frontend retry failed HTTP requests?

Retry a request only when the failure is likely temporary (a network error, a timeout, 429, 502, 503 or 504) and only when repeating it is safe: GET, PUT and DELETE are idempotent, while POST needs an idempotency key. Wait longer between attempts with exponential backoff plus random jitter, respect Retry-After, cap the number of attempts, and stop when the user leaves or cancels.

Read the full answer

Promise.all vs Promise.allSettled vs Promise.race vs Promise.any

All four take an iterable of promises and return one promise, but they decide differently. Promise.all fulfils when every input fulfils and rejects on the first failure. allSettled waits for all and never rejects. race copies the first promise to settle, either way. any fulfils with the first success and rejects only if all fail.

Read the full answer

Async/await vs promises: what is the difference?

async/await is not a separate mechanism. It is syntax built on promises. An async function always returns a promise, and await pauses that function until a promise settles, then gives you its value or throws its error. The same work can be written either way. await mainly reads like synchronous code.

Read the full answer

What is the event loop in JavaScript?

The event loop is how JavaScript runs asynchronous code on a single thread. Synchronous code runs on the call stack. When the stack is empty, the engine runs every queued microtask (promise callbacks, await continuations, queueMicrotask), the browser may render a frame, and then the loop takes the next task, such as a timer or a click, and repeats. That order is why a promise callback runs before setTimeout(fn, 0).

Read the full answer

Cache-Control: no-cache vs no-store vs max-age=0

no-cache lets caches store the response but requires them to check with the server before every reuse. no-store forbids storing it anywhere. max-age=0 makes it stale immediately, so caches normally revalidate too, but unlike no-cache it still allows stale reuse in some cases, such as when the server is unreachable. Use no-store for sensitive data and no-cache for content that must always be current.

Read the full answer

XMLHttpRequest vs fetch: what is the difference?

XMLHttpRequest (XHR) is the original event-based API for making HTTP requests from JavaScript. fetch is its modern, promise-based replacement: it works with async/await, streams response bodies, cancels with AbortController, and is the only option in service workers. Use fetch by default. XHR still has one practical advantage: built-in upload progress events.

Read the full answer

Medium62

Showing 62 of 245 medium questions. Browse the rest in the question bank

Practise with tests and full answers.

Every question has a runnable editor, tests and a step-by-step solution. Passes from ₹149, paid once; nothing renews.

Get full access
Rehearse it in a timed JavaScript mock interviewA real editor with tests, the follow-ups an interviewer asks, and a score out of 100.

Frequently asked

What are scenario-based JavaScript interview questions?

Questions that start from a real situation rather than a named function: limit how many requests run at once, retry a flaky API, cache responses that expire, cancel a search when the user types again, or batch analytics events. You choose the approach and write working code.

How should I answer a scenario-based question?

Repeat the problem back with its constraints, ask about edge cases such as errors, timeouts and ordering, sketch the approach, then code it. Finish by saying how you would test it and what you would change at a larger scale.

Are scenario-based questions asked to experienced developers?

Yes, mostly from two years of experience up. They replace puzzle questions in many SDE-2 and senior loops, because they show how you handle async code, failure and trade-offs.