└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Asynchronous programming Interview Questions 2 | 3 | > Interview questions and recommendations for JavaScript and TypeScript. 4 | > Translations: 5 | > [EN](https://github.com/tshemsedinov/Async-Interview-Questions/tree/en), 6 | > [UA](https://github.com/tshemsedinov/Async-Interview-Questions/tree/ua), 7 | > [RU](https://github.com/tshemsedinov/Async-Interview-Questions/tree/ru). 8 | 9 | 1. How can we write code to avoid blocking the event loop? 10 | 2. How can we handle a blocked event loop to exit the blocking state from the same process? 11 | 3. What is callback hell, and how can we avoid it? 12 | 4. What are async generators and iterators, how do they work, and what are their use cases? 13 | 5. How do we handle errors in async code? 14 | 6. When does try/catch capture async errors and when does it not? 15 | 7. Which async abstraction supports the `captureRejections` flag, and what is it for? 16 | 8. How can we avoid losing steps in the stack trace and improve debugging and understanding of control flow using async/await? 17 | 9. How can we cancell async operations? 18 | 10. What is the difference between async contracts: callbacks, events, async/await, promises, etc.? 19 | 11. How are async contracts (callbacks, events, async/await, promises) related, and is it possible to eliminate older ones? 20 | 12. What is the difference between `Promise.all()` and `Promise.allSettled()`? 21 | 13. What is the difference between `f2` and `f3` in the following expression: `promiseInstance.then(f1, f2).catch(f3)`? 22 | 14. When and why might we have multiple catch clauses: `promiseInstance.catch(f1).catch(f2).catch(f3)`? 23 | 15. Why do we have `Promise` method `finally`, and what are its use cases? 24 | 16. How can we write async code with sync generators? What are the advantages and disadvantages of this approach? 25 | 17. Provide examples of using `yield` in async programming. How to rewrite it in modern JavaScript? 26 | 18. Describe the differences between Web Workers, Shared Workers, and Worker Threads. 27 | 19. Describe microtasks and macrotasks and their relation to the event loop. 28 | 20. What are Worker Threads in Node.js, and how might we use this technique? 29 | 21. How can we measure I/O operations performance and resource usage? 30 | 22. What are `process.hrtime` and `process.hrtime.bigint()`, and what is the difference? 31 | 23. Tell us about the following Node.js API: `const { performance } = require('node:perf_hooks');` 32 | 24. How can we efficiently handle asynchronous API requests at the client side that return large amounts of data? 33 | 25. How can we efficiently handle API requests at the server side that return large amounts of data asynchronously? 34 | 26. How can we ensure state isolation between different asynchronous requests in a single Node.js process? 35 | 27. What is CLS (continuation local storage), and do we have a modern substitution for this async technique in Node.js? 36 | 28. Which event loop phases are related to pending callbacks? 37 | 29. Tell us about `Thenable` contract and its relation to `Promise`. 38 | 30. How can we associate some state (collection or data structure) with the chain of async calls? 39 | 31. How can we track the chain of async calls from external requests (originating from API call via HTTP, UDP, IPC, WebSocket)? 40 | 32. How can we ensure safe processing of competing requests to a resource? 41 | 33. Why do we need locks API, such as Web Locks? 42 | 34. How can we use parallel programming primitives (semaphore, mutex, critical section, etc.) in async programming? 43 | 35. Tell us about «Reactive programming» paradigm. 44 | 36. What is the difference between streams and signals approaches in reactive programming? 45 | 37. How can we handle and avoid deadlocks in asynchronous code? 46 | 38. How can we ensure high availability in asynchronous applications? 47 | 39. How can we handle asynchronous operations that depend on each other (parallel and sequential executions)? 48 | 40. What is a race condition, and how can we avoid it? 49 | 41. Provide use cases for `Promise.race`, `Promise.all`, and `Promise.allSettled`. 50 | 42. What are throttling and debouncing in the context of asynchronous programming? 51 | 43. How can we shape async calls (e.g., to limit request flow to an API)? 52 | 44. What abstractions implementing the `Observable` pattern do we have in JavaScript for backend and frontend? 53 | 45. Describe the `Signals` approach for reactive code. 54 | 46. Why are `Streams` useful to improve code semantics as a high-level abstraction? 55 | 47. What is back pressure? 56 | 48. What is the difference between creating a `Stream` with `extends` vs. passing `read`, `write`, or `transform` function to a revealing constructor? 57 | 49. Why do we have three sets of timers: in the global context (e.g., `setTimeout`), `node:timers`, and `node:timers.promises`? 58 | 50. What promisified APIs do you know, and how can we manually promisify other APIs? 59 | 51. Tell us about testing of asyncronous code. 60 | 52. Why can't TypeScript describe async contracts in all aspects? 61 | 53. How can we prevent memory leaks in async code? 62 | 54. What are the best practices for managing concurrency in JavaScript? 63 | 55. How can we use async/await with `EventEmitter`? 64 | 56. What is the difference between `EventEmitter` and `EventTarget`? 65 | 57. What is the role of the `await` keyword in async functions? 66 | 58. What happens if we use `await` with non-promise values (or expressions)? 67 | 59. How can we add timeouts in async operations (including `await` syntax)? 68 | 60. What are the implications of the `process.nextTick` method? 69 | 61. How can we create custom async iterables and what are their use cases? 70 | 62. What are the advantages and disadvantages of using third-party async libraries like `Promise` polyfills and `async.js`? 71 | 63. How can we handle async code in legacy systems? 72 | 64. What is the difference between asynchronous, parallel, and I/O operations? 73 | 65. How can we parallelize I/O operations effectively? 74 | 66. How can we ensure thread safety in async programming? 75 | 67. How are `Atomics` related to asynchronous and parallel programming? What are they used for? 76 | 68. How can we optimize async code for performance? 77 | 69. How can we handle retries (calls, calculations, resource access) in async programming? 78 | 70. What are the common pitfalls of async programming? 79 | 71. How can we use async functions with `Array.prototype.map`? 80 | 72. How can we debug async code effectively? 81 | 73. How can we ensure data consistency in async operations? 82 | 74. What are the benefits of using `async/await` over callbacks? 83 | 75. Which operations can't be rewritten from callbacks to `async/await` syntax (but are possible with `Promises`)? 84 | 76. Propose use cases for `AbortSignal.timeout()`. Which well-known APIs support it? 85 | 77. Where and for what purposes can we use `AbortSignal.any(iterable)`? 86 | 78. What are the differences between `Promise` methods: `resolve` and `reject`? 87 | 79. How can we handle errors in `Promise.all`? 88 | 80. How can we chain async operations? (Please propose cases for as many contracts as you know) 89 | 81. What is the role of the event loop in async programming? 90 | 82. How can we handle long-running async operations? (Processes may exit, results may become obsolete, etc.) 91 | 83. How can we ensure idempotency in async operations and when do we need it? 92 | 84. Can we write a real-time application in JavaScript and asynchronous programming? 93 | 85. How can we ensure the order of async operations? Please suggest cases in which we might experience problems. 94 | 86. How can we handle async code in a high-availability system? 95 | 87. What are observables and how can we use them in JavaScript? 96 | 88. What are the main problems of handling state in asynchronous code in a stateful application? 97 | 89. When can we use internal async queues and when do we need external queue systems? 98 | 90. How can we use async functions with caching, memoization, and recalculations on state updates? 99 | 91. How can we use async functions with database connections and what are the use cases? 100 | 92. How can we separate async code from business logic and why might we want to do this? 101 | 93. What is the impact of async code on CPU-bound vs I/O-bound operations? 102 | 94. What are the security considerations in async programming? 103 | 95. How can we implement a priority queue for async tasks? 104 | 96. How can we use async functions with file system operations? 105 | 97. How can we ensure atomicity in async operations and what for? 106 | 98. What are the trade-offs between using `Promise` and `async/await`? 107 | 99. What is the difference between simple async programming and the RxJS approach? 108 | 100. What are async collections and how can they improve developer experience? 109 | 110 | ## Links 111 | 112 | - [❓ Сatalog of Interview Questions](https://github.com/tshemsedinov/Interview-Questions) 113 | - [🔁 Async 2024](https://github.com/HowProgrammingWorks/Index/blob/master/Courses/Async-2024.md) 114 | - [🚀 Node.js 2024](https://github.com/HowProgrammingWorks/Index/blob/master/Courses/NodeJS-2024.md) 115 | - [🤖 Self Assessment](https://github.com/HowProgrammingWorks/SelfAssessment) 116 | --------------------------------------------------------------------------------