JavaScript & TypeScript
Scope, closures, async behavior, object identity, and the type system.
How does async JavaScript run?
Asynchronous JavaScript lets a program start work that may finish later without waiting synchronously for the result. A promise represents eventual completion, and async/await provides a readable way to work with promises. The runtime queues continuations and runs them when the current synchronous work has finished and the relevant checkpoints are reached.
Which Promise method should I use?
Promise combinators combine several promises into one result. The correct method depends on whether you need every success, every outcome, the first outcome or the first success. They observe promises; they do not automatically cancel ongoing operations when the combined result settles.
Why does forEach with async cause problems?
forEach calls a callback for each array item but ignores the values returned by those callbacks. An async callback returns a promise, so forEach does not wait for its completion or collect its rejection. Choose a loop or a promise combinator based on whether the operations depend on each other.
What causes a race condition?
A race condition happens when the result depends on the timing of operations that access shared state. JavaScript can have races even on one execution thread because asynchronous work pauses and lets other requests run between a read and a write. Databases and other processes can also update the same data concurrently.
Difficulty is an editorial estimate. Completion means you chose to mark a question as understood.