← ByteDance Interview Insights

ByteDance·Frontend Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Bytedance frontend interview that went pretty deep on JavaScript internals. The event loop question was the main focus and they really wanted you to walk through execution order, not just recite definitions.

Questions Asked (3)

Q1

Explain how the JavaScript event loop works, including the call stack, macrotask queue, and microtask queue. How does the engine decide what runs and when?

Technical Trade-offsSystem Design
Author's notes

I knew the rough shape of this answer but fumbled the ordering details under pressure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the event loop as the mechanism that coordinates the call stack, macrotask queue, and microtask queue to enable non-blocking asynchronous behavior in JavaScript. Then walk through the execution order: synchronous code runs first, then all microtasks are drained, then one macrotask is processed, repeating the cycle. Use a concrete example like setTimeout vs Promise to illustrate the priority and timing differences.

Pro tip: Emphasize that microtasks are processed completely before the next macrotask, and mention that this can lead to starvation if microtasks keep scheduling more microtasks. Also note that rendering happens between macrotasks, not microtasks, which is crucial for UI performance.

1. Define the event loop and its components

Explain that the event loop is a continuous process that monitors the call stack and task queues. Introduce the call stack (where synchronous code executes), macrotask queue (e.g., setTimeout, setInterval, I/O), and microtask queue (e.g., Promises, MutationObserver).

2. Describe the execution order

Detail the cycle: run all synchronous code on the call stack until empty, then drain the entire microtask queue, then take one macrotask from the queue and run it, then drain microtasks again, and repeat. Mention that rendering occurs between macrotasks.

3. Illustrate with a concrete example

Provide a code snippet showing the output order of console.log, setTimeout, and Promise.resolve().then. Walk through step-by-step how the event loop processes each, highlighting why microtasks run before the next macrotask.

4. Discuss implications and trade-offs

Explain how this architecture enables non-blocking I/O but can cause issues like microtask starvation or delayed rendering if misused. Mention that long-running synchronous code blocks the event loop entirely.

5. Summarize and connect to real-world scenarios

Tie back to frontend performance: how understanding the event loop helps optimize rendering, avoid jank, and debug async issues. Mention tools like Chrome DevTools Performance panel for observing task queues.

Key Points to Mention

  • The call stack executes synchronous code; when empty, the event loop checks queues.
  • Microtasks (e.g., Promise callbacks) have higher priority and are fully drained before the next macrotask.
  • Macrotasks (e.g., setTimeout, setInterval, I/O) are processed one at a time per event loop tick.
  • Rendering (style, layout, paint) occurs between macrotasks, not microtasks, affecting UI responsiveness.
  • Microtask starvation can occur if microtasks continuously enqueue more microtasks, blocking macrotasks and rendering.
  • The event loop is single-threaded but leverages Web APIs and queues to handle concurrency.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given a code snippet that mixes synchronous code, setTimeout, and Promise.then, walk through the exact execution order and explain what prints and when.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I actually felt okay.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clearly state the event loop model: synchronous code runs first, then microtasks (Promise callbacks), then macrotasks (setTimeout). Then walk through the snippet line by line, categorizing each operation and predicting the output order. Finally, explain why the order occurs, referencing the event loop phases.

Pro tip: Mention that the exact order can depend on the environment (browser vs Node.js) and the presence of other tasks, but the fundamental microtask-before-macrotask rule holds. Also, note that Promise.then callbacks are microtasks, while setTimeout callbacks are macrotasks.

1. Identify synchronous code

Scan the snippet for any code that executes immediately, such as console.log statements or function calls not wrapped in callbacks. These run first, in order.

2. Identify microtasks

Look for Promise.then, queueMicrotask, or other microtask sources. These are queued and run after the current synchronous code completes, before any macrotasks.

3. Identify macrotasks

Look for setTimeout, setInterval, or other macrotask sources. These are queued and run after all microtasks have been processed.

4. Simulate execution order

Walk through the code from top to bottom, noting when each callback is scheduled and when it will execute based on the event loop rules.

5. Explain the output order

State the exact sequence of printed messages, and briefly explain why each occurs when it does, referencing the event loop phases.

Key Points to Mention

  • The event loop processes one macrotask per iteration, then all available microtasks, then rendering (in browsers).
  • Promise.then callbacks are microtasks and have higher priority than setTimeout callbacks (macrotasks).
  • Synchronous code always runs to completion before any asynchronous callbacks.
  • setTimeout with a delay of 0 still defers execution to the next macrotask phase.
  • The order of multiple microtasks is preserved (FIFO), and the same for macrotasks.
  • In Node.js, the event loop has different phases (timers, poll, check, etc.), but the microtask queue is still processed after each phase.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

How does async/await relate to Promises under the hood? What does the runtime actually do when it hits an await expression?

Technical Trade-offs
Author's notes

Answered that await essentially pauses execution and resumes via a microtask, similar to a .then callback.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying that async/await is syntactic sugar over Promises, then walk through the transformation: an async function returns a Promise, and each await pauses execution by yielding control back to the event loop. Explain the runtime mechanics—how await wraps the expression in a Promise.resolve, suspends the async function, and schedules its continuation as a microtask once the awaited Promise settles.

Pro tip: Mention that await always defers continuation to a microtask, even if the Promise is already resolved, which explains why async functions never block and why ordering matters in microtask queues. Also note that async/await doesn't replace Promises—it uses them, so understanding Promise internals is still essential for debugging and performance.

1. Define the relationship

State that async/await is built on Promises: an async function always returns a Promise, and await is a syntactic way to consume a Promise. This sets the foundation for the deeper explanation.

2. Explain the transformation

Describe how the runtime (or transpiler) transforms await into Promise.resolve(expression).then(continuation). The async function's body after await becomes the callback passed to then.

3. Detail the suspension and resumption

Explain that when await is hit, the async function suspends, returning control to the caller and the event loop. The continuation is scheduled as a microtask when the awaited Promise settles.

4. Highlight microtask scheduling

Emphasize that even if the Promise is already resolved, the continuation runs asynchronously in a microtask, not synchronously. This ensures non-blocking behavior and consistent ordering.

5. Connect to practical implications

Tie it back to real-world impact: error handling via try/catch, debugging async stack traces, and performance considerations like avoiding unnecessary awaits in loops.

Key Points to Mention

  • Async functions always return a Promise, even if you return a non-Promise value.
  • await expression is equivalent to Promise.resolve(expression).then(...) with the rest of the function as the continuation.
  • The runtime suspends the async function at await, allowing the event loop to process other tasks.
  • Continuation after await is scheduled as a microtask, ensuring it runs after the current call stack but before macrotasks.
  • Error handling: rejected Promises become thrown exceptions inside async functions, catchable with try/catch.
  • Async/await does not block the main thread; it's still asynchronous and non-blocking.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.