Q1
Why can React stale closures inside useEffect(() => setInterval(...), []) keep reading initial count = 0 forever?
An empty [] dependency array runs the callback once and captures initial render state in its lexical closure. Either pass functional updates (setCount(c => c + 1)) or store latest mutable values in a useRef.
Q2
What happens in MongoDB if you create a compound index { status: 1, createdAt: -1 } and query ONLY by createdAt?
MongoDB B-tree indexes follow the leftmost prefix rule. Filtering solely on createdAt without status skips the compound index and triggers a full collection scan (COLLSCAN).
Q3
Why is offset pagination (skip(page * limit)) slow at page 5,000 in MongoDB, and how does cursor pagination fix it?
skip(100000) still scans and discards 100,000 index keys on every request. Cursor pagination (find({ _id: { $lt: lastId } }).sort({ _id: -1 }).limit(20)) jumps directly via index in constant O(log n) time.
Q4
How can synchronous JSON.parse or catastrophic Regex (ReDoS) freeze an entire Express server for all concurrent users?
Node runs JavaScript on a single event-loop thread. A CPU-heavy regex backtracking attack or multi-MB synchronous parse blocks every other user's HTTP request until completion.
Q5
Why does Promise.all([p1, p2, p3]) drop results from p1 and p2 if p3 rejects—and when do you use Promise.allSettled?
Promise.all fails fast on the first rejection. For dashboards fetching independent microservices where partial failure is acceptable, Promise.allSettled returns all statuses cleanly.
Q6
Why does storing React modal/filter state in useState lose context on browser Back navigation—and why does URL query state often work better?
Local useState disappears on reload or Back clicks and cannot be bookmarked or shared. Syncing search filters/pagination with URLSearchParams makes browser navigation seamless.
Q7
What subtle race condition occurs during inventory checkout in MongoDB without atomic operators or transactions?
Two concurrent checkouts reading stock = 1 in Node and both saving stock = 0 oversell inventory. Use atomic findOneAndUpdate({ _id, stock: { $gte: qty } }, { $inc: { stock: -qty } }) or multi-document ACID transactions.
Q8
Why must Express helmet() and trust proxy be configured behind Nginx or cloud load balancers?
Without app.set('trust proxy', 1), Express sees the load balancer's local IP instead of real client IPs—breaking express-rate-limit (blocking ALL users as one IP) and req.secure cookie checks.
Q9
How does React key prop key={index} corrupt input fields when items are filtered or reordered?
React matches component state by key. Using array index causes removed items to shift state/uncontrolled input values onto the wrong row. Always use stable database _id keys.
Q10
Why does Node.js uncaughtException require graceful process restart rather than continuing?
After an uncaught exception, streams, locks, and in-memory closures remain in an undefined corrupted state. Log diagnostics, stop accepting new HTTP requests (server.close()), and let PM2/Docker restart cleanly.