All 57 questions

  1. How does the JavaScript event loop work?

    Asked in 21 of 228 interviews · last asked Nov 18 · Concept · Mid-level

    Show answer

    The event loop coordinates when queued JavaScript callbacks run. Synchronous code runs on the call stack, while the browser or Node.js runtime handles asynchronous operations and queues callbacks when ready. Queued callbacks run only when the stack is empty. Promise microtasks run before the next task, such as a timer callback.

    • Long-running synchronous code blocks other callbacks from running.
    • Microtasks include Promise handlers and queueMicrotask callbacks; newly added microtasks also run before the next task.
    • A timer delay is a minimum wait, not a guaranteed execution time.
    • Node.js uses event loop phases for timers and I/O, plus a separate process.nextTick queue.
    JavaScript
    console.log('start');
    setTimeout(() => console.log('timer'), 0);
    Promise.resolve().then(() => console.log('promise'));
    console.log('end');
    // Output: start, end, promise, timer

    What the interviewer checks: The interviewer checks whether you can explain callback scheduling and predict execution order.

    Common mistake (in 4 of 6 reviewed answers): Many answers forget that the runtime handles asynchronous work and queues callbacks to run after the call stack is empty.

    Other ways it was asked
    • “What is the event loop in JavaScript?”
    • “Can you explain the event loop?”
    • “What is the event loop?”
  2. How do microtasks, timers, and await continuations run relative to synchronous code in the JavaScript event loop?

    Asked in 11 of 228 interviews · last asked Nov 4 · Concept · Senior

    Show answer

    Synchronous code finishes first, then microtasks drain before the next timer callback. Promise handlers run as microtasks when their promises settle. An await pauses its async function, and its continuation runs as a microtask, even for an already fulfilled promise.

    • Microtasks added while draining also run before the next timer; repeated microtasks can delay timers and I/O.
    • A timer delay is a minimum wait, not a guaranteed execution time.
    • Node.js process.nextTick uses a separate queue, usually drained before promise microtasks; ES modules can differ.
    • Node.js setImmediate runs in the check phase; its order against setTimeout depends on context.
    JavaScript
    console.log('start');
    setTimeout(() => console.log('timer'), 0);
    (async () => {
      await Promise.resolve();
      console.log('await');
    })();
    Promise.resolve().then(() => console.log('then'));
    console.log('end');
    // Output: start, end, await, then, timer

    What the interviewer checks: The interviewer checks whether you can predict execution order and explain how microtasks can delay other work.

    Common mistake (in 3 of 6 reviewed answers): Many answers forget that synchronous code finishes first and queued microtasks drain before the next timer callback.

    Other ways it was asked
    • “In Node.js, what's the practical difference between the event loop's microtask queue (Promises and queueMicrotask) and macrotask queue (setTimeout and setImmediate), and when would you choose one over the other?”
    • “In Node.js, what's the difference between the microtask queue (promises and process.nextTick) and the macrotask queue (setTimeout and setImmediate), and how can this affect production latency?”
    • “In JavaScript's event loop, how do microtasks (promises) and macrotasks (setTimeout) differ in scheduling, and what's the practical impact on execution order?”
  3. What is a callback function in JavaScript?

    Asked in 8 of 228 interviews · last asked Oct 27 · Concept · Junior

    Show answer

    A callback is a function passed to another function so that it can call it. Callbacks let you provide code to run during an operation or after it finishes. They can run immediately, like callbacks in array methods, or later, like timer callbacks.

    • Pass the function itself, rather than calling it and passing its result.
    • Callbacks can be synchronous or asynchronous.
    • Common uses include array methods, event handlers, and handling results from asynchronous operations.
    JavaScript
    function greet(name, callback) {
      callback(`Hello, ${name}`);
    }
    
    greet("Sam", (message) => {
      console.log(message); // Hello, Sam
    });

    What the interviewer checks: The interviewer is checking whether you understand passing functions as values and know that callbacks are not always asynchronous.

    Other ways it was asked
    • “What is a callback function?”
    • “What is a callback function used for in JavaScript?”
    • “What is a callback function, and what is it used for?”
  4. When would you use Promise.all, Promise.allSettled, or sequential awaits, and how would you handle failures?

    Asked in 7 of 228 interviews · last asked Nov 4 · Concept · Mid-level

    Show answer

    Use `Promise.all` for independent operations when you need every result. Use `Promise.allSettled` when partial success is useful and you need every outcome. Use sequential awaits when operations depend on earlier results or must run one at a time. Catch rejections from `Promise.all` and sequential awaits; with `Promise.allSettled`, inspect each result and handle failures individually.

    • `Promise.all` rejects on the first rejection, but does not cancel other operations.
    • `Promise.allSettled` waits for every operation and returns fulfilled values or rejection reasons.
    • Both return results in input order, not completion order.
    • For sequential execution, start each operation after the previous one finishes; awaiting already-started promises does not serialize them.

    What the interviewer checks: The interviewer checks whether you can choose concurrency based on dependencies and handle partial or complete failure.

    Other ways it was asked
    • “What is the difference between Promise.all and Promise.allSettled?”
    • “When you have multiple independent API calls, how do you decide between Promise.all, Promise.allSettled, and sequential awaits?”
    • “When you write an async function that awaits multiple API calls, how do you decide between running them sequentially versus in parallel with Promise.all? And how do you handle partial failures?”
  5. What is a JavaScript promise, and when would you use one?

    Asked in 7 of 228 interviews · last asked Oct 5 · Concept · Junior

    Show answer

    A JavaScript Promise is an object that represents the eventual result of an operation, usually asynchronous. It starts pending, then becomes fulfilled with a value or rejected with a reason. I use promises for tasks like network requests, so I can handle results and errors without blocking other code.

    • Once fulfilled or rejected, a promise cannot change its state or result.
    • Use .then() for success, .catch() for errors, and .finally() for cleanup.
    • These methods return new promises, so you can chain operations.
    • Async functions can use await to read promise results and try/catch to handle rejections.

    What the interviewer checks: The interviewer checks whether you understand asynchronous results, promise states, and error handling.

    Other ways it was asked
    • “What is a promise?”
    • “What is a JavaScript Promise, and how does it work?”
    • “What is a JavaScript Promise used for, and when would you use one?”
  6. Is JavaScript single-threaded or multithreaded, and how does it handle asynchronous work?

    Asked in 3 of 228 interviews · last asked Aug 25 · Concept · Mid-level

    Show answer

    JavaScript runs one piece of code at a time on each thread. Browsers and Node.js handle asynchronous operations, such as timers and network requests. The event loop lets queued callbacks run when the call stack is empty. Workers allow JavaScript to run on separate threads.

    • Asynchronous work does not mean JavaScript callbacks run in parallel on the same thread.
    • Promise callbacks run as microtasks, before the next task, such as a timer callback.
    • Long synchronous code blocks that thread, delaying queued callbacks.

    What the interviewer checks: The interviewer checks whether you can separate JavaScript execution from runtime-managed asynchronous work and explain the event loop.

    Other ways it was asked
    • “JavaScript is single-threaded, so how does it handle asynchronous tasks?”
    • “Is JavaScript single-threaded or multithreaded?”
  7. What are asynchronous operations in Node.js?

    Asked in 3 of 228 interviews · last asked Oct 19 · Concept · Junior

    Other ways it was asked
    • “Can you clarify what exactly makes an operation asynchronous in Node.js and how it differs from synchronous ones?”
    • “How does JavaScript handle asynchronous operations?”
  8. What is the difference between promises and async/await in JavaScript?

    Asked in 3 of 228 interviews · last asked Jul 28 · Concept · Junior

    Show answer

    A promise represents an asynchronous result that may succeed or fail. Async/await is syntax for working with promises, so it makes asynchronous code read more like normal step-by-step code. Use async/await for clear sequences, and promise methods such as `.then()` when chaining fits better.

    • An async function always returns a promise.
    • Await pauses the current async function, not the JavaScript thread.
    • Use try/catch around awaited operations, or .catch() on a promise chain, to handle errors.
    • For independent tasks, start them together and await Promise.all() instead of awaiting each task in sequence.
    JavaScript
    function getDataWithPromises(url) {
      return fetch(url).then(response => response.json());
    }
    
    async function getDataWithAwait(url) {
      const response = await fetch(url);
      return response.json();
    }

    What the interviewer checks: The interviewer checks whether you understand that async/await uses promises, including how waiting and error handling work.

    Other ways it was asked
    • “What is the difference between promises and async/await?”
    • “What is the difference between promises, callbacks, and async/await?”
    • “When would you use promises instead of async/await?”
  9. How can Node.js handle thousands of concurrent requests if JavaScript is single-threaded?

    Asked in 2 of 228 interviews · last asked Nov 5 · Concept · Mid-level

    Other ways it was asked
    • “How does Node.js handle multiple requests if it is single-threaded?”
  10. In Node.js, what are the event loop phases, where are setTimeout, setImmediate, and process.nextTick scheduled, and when can setImmediate run before setTimeout with a delay of zero?

    Asked in 2 of 228 interviews · last asked Nov 20 · Concept · Senior

    Other ways it was asked
    • “In Node.js, what’s the difference between process.nextTick(), setImmediate(), and setTimeout(0) in when they run relative to the event loop?”
  11. How does awaiting versus returning a promise affect whether try/catch catches its rejection?

    Asked in 2 of 228 interviews · last asked Jul 23 · Concept · Mid-level

    Other ways it was asked
    • “In async/await, what is the difference between returning await somePromise and returning somePromise inside an async function?”
    • “If you write try { return somePromise; } catch (e) { ... } inside an async function, will the catch block run if the promise rejects?”
    • “What happens if you forget await on a promise inside try/catch?”
  12. What executes first: synchronous logging, a resolved promise callback, or a zero-delay setTimeout callback, and why?

    Asked in 2 of 228 interviews · last asked Oct 1 · Concept · Mid-level

    Other ways it was asked
    • “What is the JavaScript event loop, and what is the execution order of setTimeout, a promise, and console.log?”
    • “In what order will console.log run when one log is inside setTimeout with a zero delay, one is inside Promise.resolve, and one is a plain log?”
  13. How do you cancel a fetch request with AbortController and distinguish cancellation from other errors?

    Asked in 2 of 228 interviews · last asked Jul 16 · Concept · Mid-level

    Other ways it was asked
    • “How would you implement request cancellation with fetch using AbortController, and what should you do in catch to avoid treating an abort like a real error?”
    • “What is AbortController, and how can you use it to cancel an in-flight request?”
  14. What is the difference between setTimeout and setInterval in JavaScript?

    Asked in 2 of 228 interviews · last asked Apr 16 · Concept · Junior

    Other ways it was asked
    • “Can you differentiate between setTimeout and setInterval?”
  15. What is a Promise in JavaScript?

    Asked in 2 of 228 interviews · last asked Oct 30 · Concept · Junior

    Other ways it was asked
    • “What are promises in JavaScript, and how do they work?”
  16. How can Promise.all with map be used to handle multiple asynchronous operations?

    Asked once · last asked Mar 29 · Concept · Mid-level

  17. What is callback hell, and how can it be avoided?

    Asked once · last asked Apr 16 · Concept · Mid-level

  18. How can you run a function after all five promises have completed without using `await`?

    Asked once · last asked Apr 27 · Write code · Mid-level

  19. What are some common pitfalls you watch for when dealing with promises, and how do you avoid subtle bugs like unhandled rejections or race conditions?

    Asked once · last asked May 15 · Concept · Senior

  20. If five promises are passed to Promise.all and the third one rejects, will the fourth and fifth promises still execute?

    Asked once · last asked Jun 24 · Scenario · Mid-level

  21. In a REST API handler, what problems can heavy promise or microtask chains cause for latency and throughput, and how would you mitigate them without changing correctness?

    Asked once · last asked Jul 3 · Scenario · Senior

  22. If you await inside a for...of loop over async operations, how does that affect concurrency compared to using Promise.all, and when would you choose each?

    Asked once · last asked Jul 16 · Concept · Mid-level

  23. How do you handle errors in async code, and what's the difference between callbacks, async/await, and promises?

    Asked once · last asked Jul 23 · Concept · Mid-level

  24. What is the exact log order of this code, and why? console.log(a); setTimeout(() => console.log(b), 0); Promise.resolve().then(() => console.log(c)); console.log(f); async function d() { console.log(d); await 0; console.log(e); } d();

    Asked once · last asked Jul 26 · Write code · Mid-level

  25. How would you implement an async function that fetches data from multiple cards, renders them as each resolves, and still handles partial failures without blocking the rest?

    Asked once · last asked Jul 26 · Write code · Senior

  26. When would you choose Promise.allSettled over Promise.all with per-promise catch, and what are the tradeoffs for error visibility and cancellation or abort behavior?

    Asked once · last asked Jul 26 · Concept · Senior

  27. In a fetch wrapper using async/await, how would you implement request deduplication so concurrent calls to the same URL share one in-flight promise, and the cache is cleared after it settles?

    Asked once · last asked Jul 26 · Write code · Senior

  28. How would you prevent an older request from overwriting newer UI data when it resolves late, using modern JavaScript patterns?

    Asked once · last asked Jul 26 · Scenario · Senior

  29. What does setTimeout actually do?

    Asked once · last asked Jul 31 · Concept · Junior

  30. How does the JavaScript event loop handle a synchronous for loop that runs a million times?

    Asked once · last asked Sep 23 · Concept · Mid-level

  31. How would you implement `Promise.all`, and what edge cases would you account for?

    Asked once · last asked Oct 7 · Write code · Senior

  32. In a debounced search component, the first two API responses update the browser, but the third and fourth do not. What could cause this, and how would you troubleshoot it?

    Asked once · last asked Oct 12 · Scenario · Senior

  33. When integrating back-end APIs into your front-end projects, how do you typically manage asynchronous data fetching to ensure smooth user interactions?

    Asked once · last asked Oct 16 · Scenario · Mid-level

  34. What happens when a setInterval callback takes longer than its delay, and can callbacks overlap?

    Asked once · last asked Dec 29 · Concept · Mid-level

    Other ways it was asked
    • “If a setInterval callback takes longer than the interval delay to complete, when does the next callback run?”
    • “Can setInterval callbacks overlap, or can delays cause many callbacks to run at the same time?”
  35. How can you use recursive setTimeout calls to achieve behavior similar to setInterval?

    Asked once · last asked Dec 29 · Concept · Mid-level

  36. Implement a synchronous sleep function in JavaScript.

    Asked once · last asked Oct 28 · Write code · Mid-level

    Other ways it was asked
    • “Implement an asynchronous sleep function in JavaScript that does not block the server.”
  37. How can a web interface prevent stale data from appearing after a user switches organizations?

    Asked once · last asked Oct 26 · Scenario · Senior

  38. How would you sequence API calls when one call depends on the result of another?

    Asked once · last asked Oct 27 · Scenario · Mid-level

  39. How does a browser handle API requests and callbacks?

    Asked once · last asked Oct 27 · Concept · Senior

  40. How do you prevent an older API response from overriding the latest search results?

    Asked once · last asked Nov 3 · Scenario · Mid-level

  41. What is the difference between microtasks and macrotasks, and how does the event loop prioritize them?

    Asked once · last asked Nov 4 · Concept · Mid-level

  42. What are microtasks and macrotasks? Could you demonstrate them with code?

    Asked once · last asked Nov 4 · Concept · Mid-level

  43. What are promises, and how do promise chaining and error propagation work?

    Asked once · last asked Nov 4 · Concept · Mid-level

  44. In Node.js, what's the difference between a promise rejection you await inside try/catch versus a promise that rejects without being awaited or handled? What does Node do in each case?

    Asked once · last asked Nov 5 · Concept · Senior

  45. In Node.js event loop terms, where does process.nextTick run relative to the microtask queue, promise callbacks, and macrotasks like setTimeout?

    Asked once · last asked Nov 5 · Concept · Senior

  46. How does async/await behave inside forEach, and why might the output differ from the expected order?

    Asked once · last asked Nov 6 · Concept · Mid-level

  47. When users make rapid consecutive edits, how do you prevent stale async responses from overwriting newer state, and how do you surface conflicts to the user?

    Asked once · last asked Nov 18 · Scenario · Senior

  48. Which browser API can you use to request new products from a backend?

    Asked once · last asked Nov 18 · Concept · Junior

  49. What is the difference between synchronous and asynchronous JavaScript?

    Asked once · last asked May 29 · Concept · Junior

  50. How does error handling work with try/catch and promises in JavaScript?

    Asked once · last asked Jul 20 · Concept · Mid-level

  51. How can you call a REST API from a front end?

    Asked once · last asked Sep 30 · Concept · Junior

  52. What does synchronous execution mean in JavaScript?

    Asked once · last asked Oct 5 · Concept · Junior

  53. What is the difference between callbacks and promises?

    Asked once · last asked Oct 7 · Concept · Junior

  54. What is asynchrony in JavaScript, and how does it work?

    Asked once · last asked Oct 8 · Concept · Mid-level

  55. Is JavaScript synchronous or asynchronous by default?

    Asked once · last asked Oct 19 · Concept · Junior

  56. Can you write code using JavaScript's setTimeout function?

    Asked once · last asked Oct 26 · Write code · Junior

  57. Does forEach wait for asynchronous callbacks to finish?

    Asked once · last asked Nov 6 · Concept · Mid-level

More JavaScript interview questions

How this list is made

Every question here was asked by a real interviewer in a real job interview that a candidate ran MeetAssist in. After the call, the interviewer's questions are pulled from the transcript. Practice sessions, tests, exams and anything that was not a job interview are dropped.

Questions are rewritten so they make sense on their own: names of people, employers and clients are removed, and speech-to-text mistakes are fixed. Small talk, logistics and questions about one candidate's own résumé are left out. Rephrasings of the same question are merged, and the count is the number of different interviews it came up in.

The interviews come from candidates who use MeetAssist, so they lean towards software, data and AI roles: the shares describe these interviews, not every JavaScript interview. Answers to the most asked questions are written and checked by an editor; a "common mistake" is shown only when reviews of real answers in these interviews show it, with the count.

228 interviews, 160 candidates, Nov 2025 to Nov 2026. Updated every month with new interviews.