React Interview Questions –
What is hoisting? Let/var/const – all are hoisted?
1)How JS works?
What is event loop? – microtask and macro task
2)what is event loop?
Event Loop coordinates between:
Call stack
Microtasks: Promise.then, queueMicrotask
Macrotasks: setTimeout, setInterval, setImmediate
3) Object questions -
4) What is currying? Write a simple curry function
function sum(a) {
return function(b) {
return function(c) {
return a + b + c;
sum(1)(2)(3); // 6
Explain JavaScript's prototype inheritance.
What is the difference between call, apply, and bind?
Difference between deep and shallow copy.
_proto__ vs prototype in JavaScript
5) Memory, Performance & GC
How does garbage collection work in JS?
Answer:
JS uses mark-and-sweep:
If a variable is reachable from the root (window, global), it's kept.
If it's not referenced anymore → marked for collection.
Avoid memory leaks by:
Clearing intervals/timeouts
Avoiding closures holding large data
Removing event listeners
I/o and o/p
console.log("start");
setTimeout(() => console.log("timeout"), 0);
Promise.resolve().then(() => console.log("promise"));
console.log("end");
--------------------------------------------------------
console.log(typeof []);
const obj = { name: "Ajay" };
Object.freeze(obj);
obj.name = "Vikram";
console.log(obj.name);
const obj = {
a: 1,
valueOf() { return 10; },
toString() { return "5"; }
};
console.log(obj + 1);
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
const a = {};
const b = { key: "b" };
const c = { key: "c" };
a[b] = 123;
a[c] = 456;
console.log(a[b]);
sol –
a["[object Object]"] = 123;
a["[object Object]"] = 456;
op- 456
let obj = { a: 1 };
let clone = Object.assign({}, obj);
clone.a = 100;
console.log(obj.a);
Object.assign() creates a shallow copy, so primitive values are not linked.
const obj = {};
Object.freeze(obj);
obj.a = 10;
console.log(obj.a);
//undefined
const obj = {
a: 1,
b: 2,
a: 3
};
console.log(obj);
Implement a deep clone function.
function deepClone(obj) {
if (obj === null || typeof obj !== "object") return obj;
if (Array.isArray(obj)) {
return obj.map(deepClone);
const copy = {};
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
copy[key] = deepClone(obj[key]);
return copy;}
REACT Questions
How does React reconcile changes in the virtual DOM?
React uses the Reconciliation Algorithm based on a diffing process:
It compares old and new virtual DOM trees.
By default, it uses keys to identify elements and minimize re-renders.
If keys change, React will destroy and re-create DOM nodes instead of reusing.
What causes unnecessary re-renders and how can you prevent them?
Causes:
Parent re-renders
Props passed as new object/function instances
Unoptimized React.memo usage
Solutions:
React.memo with proper comparison
useCallback, useMemo
Splitting large components
key optimization
What is the difference between useCallback and useMemo?
How does React.lazy work under the hood?
React.lazy() uses dynamic import() to load components asynchronously.
It returns a promise-based component wrapper.
Should be used with <Suspense> to handle loading/fallback UI
const LazyComponent = React.lazy(() => import('./Component'));
What is React Fiber?
Fiber is the new reconciliation engine in React.
Enables interruptible rendering, prioritization, and time slicing.
Converts rendering into a tree of units of work that can be paused, resumed,
aborted.
Difference between controlled and uncontrolled components?
Whats I RTK, slice, why use slice?
How does useImperativeHandle work? When to use it?
Answer:
Used to customize the instance value that is exposed to parent components via ref.
js
CopyEdit
useImperativeHandle(ref, () => ({
focus: () => inputRef.current.focus()
}));
Used when:
You want parent to control internal component methods.
How would you optimize rendering in a large React application?
React.memo, useMemo, useCallback
Code splitting (React.lazy)
Debounce/throttle input updates
Virtualize large lists (e.g. react-window)
Avoid anonymous props/functions
Use key properly in lists
WEBPACK questions -
How do you implement Micro-Frontends using Webpack Module Federation?
Use Webpack 5’s Module Federation Plugin.
Host (Shell): loads remote components.
Remote: exposes components for consumption.
// Remote
new ModuleFederationPlugin({
name: "remoteApp",
filename: "remoteEntry.js",
exposes: {
'./Button': './src/components/Button',
},
})
// Host
new ModuleFederationPlugin({
remotes: {
remoteApp: 'remoteApp@http://localhost:3001/remoteEntry.js',
},
})
How do Micro-Frontends communicate with each other?
Props (if shared via React context)
Custom events (e.g., window.dispatchEvent)
Pub/Sub libraries (like RxJS, mitt)
Shared Redux/Context (via singleton host)
Browser storage (localStorage/sessionStorage)
How do you share dependencies (like React) in Module Federation?
shared: {
react: { singleton: true, requiredVersion: '^18.0.0' },
'react-dom': { singleton: true },
}
REACT OUTPUT questions
function App() {
const [count, setCount] = React.useState(0);
React.useEffect(() => {
setCount(1); }, []);
return <p>{count}</p>;
}
--------------------------------------------------------------------------------
function App() {
const [count, setCount] = React.useState(0);
const handleClick = () => {
setCount(count + 1);
setCount(count + 1);
};
return <button onClick={handleClick}>{count}</button>;
}
Can you implement a custom useDebounce hook?
function useDebounce(value, delay) {
const [debounced, setDebounced] = useState(value);
useEffect(() => {
const handler = setTimeout(() => setDebounced(value), delay);
return () => clearTimeout(handler);
}, [value, delay]);
return debounced;
}