Interview questions and recommendations for JavaScript and TypeScript. Translations: EN, UA, RU.
- How can we write code to avoid blocking the event loop?
- How can we handle a blocked event loop to exit the blocking state from the same process?
- What is callback hell, and how can we avoid it?
- What are async generators and iterators, how do they work, and what are their use cases?
- How do we handle errors in async code?
- When does try/catch capture async errors and when does it not?
- Which async abstraction supports the
captureRejections
flag, and what is it for? - How can we avoid losing steps in the stack trace and improve debugging and understanding of control flow using async/await?
- How can we cancell async operations?
- What is the difference between async contracts: callbacks, events, async/await, promises, etc.?
- How are async contracts (callbacks, events, async/await, promises) related, and is it possible to eliminate older ones?
- What is the difference between
Promise.all()
andPromise.allSettled()
? - What is the difference between
f2
andf3
in the following expression:promiseInstance.then(f1, f2).catch(f3)
? - When and why might we have multiple catch clauses:
promiseInstance.catch(f1).catch(f2).catch(f3)
? - Why do we have
Promise
methodfinally
, and what are its use cases? - How can we write async code with sync generators? What are the advantages and disadvantages of this approach?
- Provide examples of using
yield
in async programming. How to rewrite it in modern JavaScript? - Describe the differences between Web Workers, Shared Workers, and Worker Threads.
- Describe microtasks and macrotasks and their relation to the event loop.
- What are Worker Threads in Node.js, and how might we use this technique?
- How can we measure I/O operations performance and resource usage?
- What are
process.hrtime
andprocess.hrtime.bigint()
, and what is the difference? - Tell us about the following Node.js API:
const { performance } = require('node:perf_hooks');
- How can we efficiently handle asynchronous API requests at the client side that return large amounts of data?
- How can we efficiently handle API requests at the server side that return large amounts of data asynchronously?
- How can we ensure state isolation between different asynchronous requests in a single Node.js process?
- What is CLS (continuation local storage), and do we have a modern substitution for this async technique in Node.js?
- Which event loop phases are related to pending callbacks?
- Tell us about
Thenable
contract and its relation toPromise
. - How can we associate some state (collection or data structure) with the chain of async calls?
- How can we track the chain of async calls from external requests (originating from API call via HTTP, UDP, IPC, WebSocket)?
- How can we ensure safe processing of competing requests to a resource?
- Why do we need locks API, such as Web Locks?
- How can we use parallel programming primitives (semaphore, mutex, critical section, etc.) in async programming?
- Tell us about «Reactive programming» paradigm.
- What is the difference between streams and signals approaches in reactive programming?
- How can we handle and avoid deadlocks in asynchronous code?
- How can we ensure high availability in asynchronous applications?
- How can we handle asynchronous operations that depend on each other (parallel and sequential executions)?
- What is a race condition, and how can we avoid it?
- Provide use cases for
Promise.race
,Promise.all
, andPromise.allSettled
. - What are throttling and debouncing in the context of asynchronous programming?
- How can we shape async calls (e.g., to limit request flow to an API)?
- What abstractions implementing the
Observable
pattern do we have in JavaScript for backend and frontend? - Describe the
Signals
approach for reactive code. - Why are
Streams
useful to improve code semantics as a high-level abstraction? - What is back pressure?
- What is the difference between creating a
Stream
withextends
vs. passingread
,write
, ortransform
function to a revealing constructor? - Why do we have three sets of timers: in the global context (e.g.,
setTimeout
),node:timers
, andnode:timers.promises
? - What promisified APIs do you know, and how can we manually promisify other APIs?
- Tell us about testing of asyncronous code.
- Why can't TypeScript describe async contracts in all aspects?
- How can we prevent memory leaks in async code?
- What are the best practices for managing concurrency in JavaScript?
- How can we use async/await with
EventEmitter
? - What is the difference between
EventEmitter
andEventTarget
? - What is the role of the
await
keyword in async functions? - What happens if we use
await
with non-promise values (or expressions)? - How can we add timeouts in async operations (including
await
syntax)? - What are the implications of the
process.nextTick
method? - How can we create custom async iterables and what are their use cases?
- What are the advantages and disadvantages of using third-party async libraries like
Promise
polyfills andasync.js
? - How can we handle async code in legacy systems?
- What is the difference between asynchronous, parallel, and I/O operations?
- How can we parallelize I/O operations effectively?
- How can we ensure thread safety in async programming?
- How are
Atomics
related to asynchronous and parallel programming? What are they used for? - How can we optimize async code for performance?
- How can we handle retries (calls, calculations, resource access) in async programming?
- What are the common pitfalls of async programming?
- How can we use async functions with
Array.prototype.map
? - How can we debug async code effectively?
- How can we ensure data consistency in async operations?
- What are the benefits of using
async/await
over callbacks? - Which operations can't be rewritten from callbacks to
async/await
syntax (but are possible withPromises
)? - Propose use cases for
AbortSignal.timeout()
. Which well-known APIs support it? - Where and for what purposes can we use
AbortSignal.any(iterable)
? - What are the differences between
Promise
methods:resolve
andreject
? - How can we handle errors in
Promise.all
? - How can we chain async operations? (Please propose cases for as many contracts as you know)
- What is the role of the event loop in async programming?
- How can we handle long-running async operations? (Processes may exit, results may become obsolete, etc.)
- How can we ensure idempotency in async operations and when do we need it?
- Can we write a real-time application in JavaScript and asynchronous programming?
- How can we ensure the order of async operations? Please suggest cases in which we might experience problems.
- How can we handle async code in a high-availability system?
- What are observables and how can we use them in JavaScript?
- What are the main problems of handling state in asynchronous code in a stateful application?
- When can we use internal async queues and when do we need external queue systems?
- How can we use async functions with caching, memoization, and recalculations on state updates?
- How can we use async functions with database connections and what are the use cases?
- How can we separate async code from business logic and why might we want to do this?
- What is the impact of async code on CPU-bound vs I/O-bound operations?
- What are the security considerations in async programming?
- How can we implement a priority queue for async tasks?
- How can we use async functions with file system operations?
- How can we ensure atomicity in async operations and what for?
- What are the trade-offs between using
Promise
andasync/await
? - What is the difference between simple async programming and the RxJS approach?
- What are async collections and how can they improve developer experience?