Core JavaScript
- Difference between
var,let, andconst. - Explain
hoistingin JavaScript. - Difference between
==and===. - Explain
thiskeyword in different contexts (global, function, class, arrow function). - Difference between
call,apply, andbind. - Event bubbling vs event capturing.
- What is closure? Give example.
- Difference between
nullandundefined. - Difference between
map,forEach,filter,reduce. - What is IIFE (Immediately Invoked Function Expression)?
- Difference between synchronous and asynchronous JavaScript.
- What is the event loop? Explain microtasks and macrotasks.
- Difference between shallow copy and deep copy — how to implement.
- Difference between
Object.assign()and spread operator. - Explain prototype and prototype chain.
- Explain ES6 modules and CommonJS modules difference.
- What are Promises and how do they work?
- Difference between
async/awaitand.then/.catch(). - How does garbage collection work in JS?
- Difference between
for…inandfor…of.
Advanced / Scenario-Based JS
- Implement debounce and throttle functions — explain use case.
- Difference between
mutableandimmutableobjects in JS. - Explain memory leak scenarios in JS and how to prevent.
- Implement a function to deep clone nested objects.
- Difference between
setTimeout(fn, 0)andPromise.resolve().then(fn). - Explain Symbol and its usage.
- Difference between generator function and async generator.
- How to handle large array processing without blocking UI (chunking).
- Explain
WeakMapandWeakSet. - Difference between
Object.freeze()andconstin objects.
Tricky JavaScript Questions (Advanced)
- What's the output?
javascript
console.log(typeof typeof 1);
console.log(0.1 + 0.2 === 0.3);
console.log([] == ![]);
console.log(+'10' + 5);
- Explain the execution order:
javascript
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');
- Temporal Dead Zone (TDZ) — explain with example and why it exists.
- What happens when you do this?
javascript
const obj = { a: 1 };
const arr = [obj, obj];
arr[0].a = 2;
console.log(arr[1].a); *// ?*
- Explain currying — implement a curry function that works for any function.
- What's wrong with this code?
javascript
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}
How to fix it? (Multiple solutions)
- Implement a pipe/compose function — explain the difference.
- Explain Proxy and Reflect API — practical use case (e.g., validation).
- What is the difference between
Object.create(null)and{}? - Implement a function that executes promises in sequence (not parallel).
- Explain the difference between:
javascript
`function foo() { return { bar: "hello" }; }
function foo() {
return
{ bar: "hello" };
}`
-
What is the
newkeyword doing internally? Implement your ownnewoperator. - Explain tail call optimization — does JS support it?
- Implement a memoization function that works for any function with any number of arguments.
- What's the output and why?
javascript
`const promise = new Promise((resolve) => {
console.log(1);
resolve();
console.log(2);
});
promise.then(() => console.log(3));
console.log(4);`
- How do you detect if a function is called with
new? - Implement
Promise.all,Promise.race, andPromise.allSettledfrom scratch. - What is the difference between
Promise.then()chaining andasync/awaiterror propagation? - Explain the "double equals quirks":
javascript
`[] == ![] *// true*
{} == !{} *// false*
[] == [] *// false*`
-
What's the difference between
argumentsand rest parameters? Why avoidarguments?
Advanced Memory & Performance Questions
- Memory leak scenario: Event listeners not removed — how to detect and fix?
- Explain V8's garbage collection algorithms: Mark-and-sweep, Scavenge, Major GC.
- How to profile memory usage in Node.js? Tools and approaches.
- What causes memory leaks in closures? Give specific example.
- Explain hidden classes and inline caching in V8 — how to write optimized code?
-
What is the
-max-old-space-sizeflag? When to use it? - How do you handle 10GB file processing in Node.js without loading it all into memory?
- Implement a LRU (Least Recently Used) cache with O(1) get and put operations.
- Explain memory fragmentation — how does it affect Node.js applications?
- How to detect and fix event loop blocking in production?
React / Next.js / State Management Questions
React Core
- Difference between class components and functional components.
- What is virtual DOM and how React uses it?
- Explain React lifecycle methods (class) and hooks equivalents.
- Explain useState and useEffect — common pitfalls.
- Explain useMemo and useCallback — when and why to use.
- Difference between controlled and uncontrolled components.
- Explain React context API and its use case.
- How to prevent unnecessary re-renders in React.
- Difference between key props in lists — why important.
- Explain reconciliation in React.
React Advanced / Optimization
- Explain code splitting and lazy loading in React.
- Difference between React.memo, PureComponent, and useMemo.
- How to optimize React app performance — list techniques.
- Explain event delegation in React.
- How to handle large forms efficiently.
- How to handle error boundaries in React.
- What is Suspense and Concurrent Mode in React.
- Difference between client-side rendering and server-side rendering.
React Advanced & Tricky Questions
- What's wrong with this code?
javascript
function Component() {
const [count, setCount] = useState(0);
const handleClick = () => {
setCount(count + 1);
setCount(count + 1);
setCount(count + 1);
};
return <button onClick={handleClick}>{count}</button>;
}
How to fix it? Explain batching.
- Explain the difference between:
javascript
useEffect(() => { */* ... */* }, []);
useEffect(() => { */* ... */* });
useLayoutEffect(() => { */* ... */* }, []);
- Why is this an infinite loop?
javascript
useEffect(() => {
setData(fetchData());
}, [data]);
- Implement a custom hook for debounced value.
- What's the difference between:
javascript
<Component data={data} />
<Component data={[...data]} />
- Explain stale closures in React hooks — give example and solution.
- How to share stateful logic between components without Context or Redux? (Custom hooks)
-
What's the purpose of the
keyprop in React? Why not use index as key? - Implement useReducer from scratch — explain when to use it over useState.
- Explain React Fiber architecture — how it enables concurrent rendering.
- How does React decide when to batch state updates? Automatic batching in React 18.
- What's the difference between
flushSyncand normal state updates? - How to prevent child component re-render when parent re-renders? (Multiple techniques)
- Explain React's reconciliation algorithm — Diff algorithm in detail.
- What happens when you call setState in render method? Why is it dangerous?
-
Implement a custom
usePrevioushook that returns previous value of a state. - How to handle race conditions in useEffect with API calls?
- Explain ref forwarding and useImperativeHandle — when to use?
- What's the difference between synthetic events and native events in React?
- How to optimize context to prevent unnecessary re-renders? Split context technique.
Next.js Advanced Questions
- Difference between SSR, SSG, ISR, and CSR in Next.js.
- Explain getServerSideProps vs getStaticProps.
- Explain API routes in Next.js.
- How to implement dynamic routing in Next.js.
- Explain Next.js image optimization.
- How to handle authentication in Next.js (JWT, cookies).
- Explain incremental static regeneration (ISR).
- How to optimize Next.js app performance (bundle splitting, caching).
Next.js Advanced & Tricky
- How does Next.js handle automatic code splitting? Can you control it?
-
Explain the difference between
next/linkand regular anchor tags — prefetching behavior. - How to implement middleware in Next.js 13+? Use cases and limitations.
- Explain App Router vs Pages Router — migration strategy.
- How to handle environment variables securely in Next.js? NEXT_PUBLIC_ prefix.
- What's the difference between:
javascript
`export const revalidate = 60; *// ISR*
export const dynamic = 'force-dynamic'; *// SSR*
export const dynamic = 'force-static'; *// SSG*`
- How to implement edge functions in Next.js? Difference from serverless.
- Explain streaming SSR in Next.js 13+ — Suspense boundaries.
- How to optimize fonts in Next.js? next/font system.
-
What happens when you use
use clientdirective? Bundle implications. - How to handle SEO for dynamic routes? generateMetadata function.
- Explain parallel and intercepting routes in App Router.
Redux / State Management
- Difference between Redux and React context.
- Explain Redux flow — actions, reducers, store.
- How to avoid unnecessary re-renders with Redux.
- Difference between middleware in Redux — thunk, saga.
- How to structure Redux state for large apps.
- Explain Redux Toolkit and why it's preferred.
- How to handle async API calls in Redux.
- How to persist Redux state in localStorage/sessionStorage.
Redux Advanced & Tricky
- Why is Redux state immutable? What happens if you mutate?
- Explain Redux middleware — implement a custom logger middleware.
- What's the difference between:
javascript
`useSelector(state => state.user)
useSelector(state => ({ user: state.user }))`
Re-render implications.
How does Redux Toolkit's
createSlicework under the hood? Immer integration.Explain Redux Saga effects:
call,put,take,fork,spawn.How to handle optimistic updates in Redux?
What's the difference between
combineReducersand a single reducer?How to implement time-travel debugging? Redux DevTools internals.
Explain selectors and reselect library — memoization benefits.
How to handle authentication state in Redux? Token refresh flow.
What's the difference between Redux Thunk and Redux Saga? When to use each?
How to test Redux reducers and actions? Best practices.
Top comments (0)