Question:
You have a large React application where a parent component re-renders frequently due to real-time data updates (WebSocket/Kafka consumer via backend). This causes performance issues in deeply nested child components.
How would you:
Identify unnecessary re-renders?
Prevent them without breaking data consistency?
Decide when to use React.memo, useCallback, useMemo, or state colocation?
Handle stale closures when optimizing?
A Node.js service handling high-throughput REST APIs starts showing increased latency and occasional timeouts under load, even though CPU usage is low.
How would you:
Diagnose whether the issue is related to the event loop?
Identify blocking operations or memory leaks?
How does JavaScript handle memory management, and what causes memory leaks in JS applications?
(Garbage collection, references, closures, event listeners, timers.)
Explain the difference between the microtask queue and macrotask queue. Why does it matter?
(Promises vs setTimeout, execution order.)
What happens internally when you use async/await? How is it different from Promises?
(Syntactic sugar, state machine, error handling.)
How does prototype inheritance work in JavaScript?
(Prototype chain, __proto__, Object.create, method lookup.)
What are shallow copy and deep copy? How would you implement them safely in JavaScript?
(Reference types, structured cloning, pitfalls.)
Decide between vertical scaling, clustering, or moving work to worker threads?
Ensure graceful degradation under traffic spikes?
Write a function that takes a string and returns the first non-repeating character in the string.
If all characters repeat, return null.