Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
JavaScript 10 questions

Event Loop and Asynchronous JavaScript

Understand how JavaScript achieves concurrency. Study call stack, callback queue, microtask queue, Web APIs, and the event loop cycle.

More JavaScript
Interview questions 1–10 of 10
1

What is the call stack in JavaScript and how does it relate to being single-threaded?

The call stack is a data structure that tracks function calls - each time a function is invoked, a frame is pu...

Read answer →
2

What are Web APIs and how do they enable asynchronous behavior in JavaScript?

Web APIs (like setTimeout, fetch, DOM events) are provided by the browser (or Node.js runtime), not the JavaSc...

Read answer →
3

What is the difference between macrotasks and microtasks in the event loop?

Queue typeExamplesPriorityMicrotask queuePromise .then/.catch/.finally, queueMicrotask, MutationObserverHigher...

Read answer →
4

How does the event loop actually work step by step?

The event loop is the mechanism that continuously checks whether the call stack is empty, and if so, moves que...

Read answer →
5

Why does setTimeout(fn, 0) not run immediately?

Even with a 0ms delay, setTimeout's callback is placed in the macrotask queue and must wait for the current sy...

Read answer →
6

How does async/await interact with the event loop compared to raw Promises?

async/await doesn't change how the event loop fundamentally works - it's still built on Promises and microtask...

Read answer →
7

What is the difference between setTimeout and setInterval, and how do you clear them?

FunctionBehaviorClear withsetTimeoutRuns the callback ONCE after the delayclearTimeout(id)setIntervalRuns the...

Read answer →
8

How does JavaScript handle concurrency without multiple threads?

JavaScript achieves concurrency through non-blocking I/O and the event loop, rather than through true parallel...

Read answer →
9

What is 'starvation' in the event loop and how can microtasks cause it?

Since the microtask queue must be FULLY drained before the event loop moves to the next macrotask, a microtask...

Read answer →
10

How would you predict the output order of a code snippet mixing sync code, setTimeout, and Promises?

Predicting execution order requires classifying every line into one of three buckets: synchronous, microtask,...

Read answer →