What are the benefits of React?
✅ Benefits of ReactJS (For Interviews)
- Component-Based Architecture
- Encourages reusability and separation of concerns.
- Makes code more modular, readable, and maintainable.
- Virtual DOM for Better Performance
- React uses a virtual DOM to minimize direct DOM manipulation.
- Improves app speed by updating only the changed components.
- Unidirectional Data Flow
- Data flows in one direction, making it easier to debug and predict how the app behaves.
- Strong Ecosystem and Community Support
- Large community means more libraries, tools, and faster problem solving.
- Well-supported by Facebook and widely adopted in the industry.
- JSX – JavaScript + HTML
- JSX simplifies writing UI logic and makes the code easier to understand.
- Rich Developer Tools
- React DevTools extension helps in debugging and inspecting component hierarchies.
- Easy to Learn and Use
- Developers with JavaScript knowledge can quickly learn and use React effectively.
- SEO-Friendly with SSR
- React can be rendered on the server side (e.g., using Next.js), making it better for SEO.
- Strong Integration Capabilities
- Easily integrates with other libraries or frameworks like Redux, React Router, Axios, etc.
- Cross-Platform Development
- Can be used to build web apps (React) and mobile apps (React Native) with shared logic.
You can end by saying:
"Overall, React’s simplicity, flexibility, and performance make it a powerful tool for building modern, scalable user interfaces."
✅ Difference Between State and Props in React
✅ Quick Analogy:
- Props = function parameters → passed in, read-only.
- State = variables inside a function → can change based on logic/events.
🧠 Sample Interview Answer:
“Props are used to pass data from parent to child components and are immutable. State, on the other hand, is local to the component and used to track data that can change over time, like form input or toggles. Props make components reusable, while state helps manage interactivity.”
What is the component lifecycle in functional components?
Summary:
- Mount → empty dependency array (
[]) - Update → dependency array with specific state/props (
[count]) - Unmount → return a function inside
useEffect
You can say in your interview:
"In functional components, we use theuseEffecthook to handle lifecycle events. It can mimiccomponentDidMount,componentDidUpdate, andcomponentWillUnmountdepending on how the dependencies are managed."
What are Hooks in React?
Hooks are special functions introduced in React 16.8 that let you use state and other React features (like lifecycle methods) in functional components, without writing a class.
Some common hooks:
useState– for managing local stateuseEffect– for side effects (e.g., API calls, timers)useRef– for referencing DOM elements or persisting values without re-rendering
When is the useRef Hook Used?
useRef is used when you want to:
- Access or interact with DOM elements directly (like focusing an input field).
- Store mutable values that persist across renders but don’t trigger re-renders when changed (like a timeout ID or previous value).
Interview Tip:
"useRef is ideal when I need to persist values across renders or directly access DOM elements without causing a re-render. It’s often used for focus control, timers, or tracking previous values."How do you avoid re-rendering of a component?
"I use React.memo to memoize components, and useMemo/useCallback to prevent unnecessary recalculations or function recreations. I also ensure object references don’t change unless needed and avoid unnecessary state updates to reduce re-renders."
How to Avoid Re-Rendering in React
React.memo()– Wrap functional components to memoize them so they only re-render when props change.
useMemo()– Memoizes expensive computations to avoid recalculating on every render.
useCallback()– Prevents function re-creation on every render, useful when passing callbacks to child components.
const handleClick = useCallback(() => {
- Avoid Changing References – Don’t recreate objects/arrays/functions inside render unless necessary.
- Use
keyproperly in lists – Helps React identify which items changed and avoid unnecessary DOM updates. - Split Large Components – Break down large components into smaller ones to isolate re-renders.
How to Optimize a React Application
- Use
React.memo - Prevents unnecessary re-renders of functional components by memoizing them unless props change.
- Use
useMemoanduseCallback useMemo→ Memoizes expensive calculations.useCallback→ Memoizes function instances to avoid re-creating them on every render.- Code Splitting with
React.lazy&Suspense - Load components only when needed (lazy loading) to reduce initial bundle size.
- Virtualize Long Lists
- Use libraries like
react-windoworreact-virtualizedto render only visible items in large lists. - Optimize Images and Assets
- Compress images, use lazy loading (
loading="lazy"), and serve scaled versions based on screen size. - Avoid Anonymous Functions in JSX
- They create new instances on every render – move them outside the render or use
useCallback. - Debounce or Throttle Expensive Events
- For input handling, scroll, or resize events, use debounce/throttle to reduce excessive re-renders.
- Remove Unused State or Props
- Keep your component clean and minimal – less state means fewer updates and re-renders.
- Keep Component Tree Shallow
- Avoid deeply nested components – it makes debugging and performance optimization harder.
🧠 Interview Summary Line:
"To optimize a React app, I use memoization (React.memo,useMemo,useCallback), lazy loading, virtualized lists, and avoid unnecessary renders by minimizing state and avoiding anonymous functions inside JSX."
What are Higher-Order Components (HOCs)?
A Higher-Order Component is a function that takes a component and returns a new one with additional behavior. I use HOCs to reuse logic like logging, authentication, or conditional rendering across multiple components.
✅ What is the Virtual DOM in React?
The Virtual DOM (V-DOM) is a lightweight JavaScript representation of the real DOM. React uses it to track changes in the UI efficiently.
Instead of directly manipulating the real DOM (which is slow), React first updates the virtual DOM, calculates the difference (diffing), and then updates only the changed parts in the real DOM.
🚀 How Does It Improve Performance?
- Minimizes Direct DOM Manipulations: Real DOM updates are expensive; virtual DOM reduces the number of these operations.
- Efficient Diffing: React compares the old and new virtual DOM and finds the minimal set of changes.
- Batch Updates: React batches updates to the real DOM, reducing reflows and repaints.
🧠 Interview Summary:
"The Virtual DOM is a copy of the real DOM stored in memory. React uses it to detect changes efficiently and update only what's necessary in the real DOM, which significantly improves app performance."
✅ Steps to Handle a 404 Page in React Router (v6+):
- Define a fallback route with
*as the path. - Place it at the end of your route list.
- Render your custom 404 component there.
🧩 Example:
🧠 Interview Summary:
"In React Router, I handle 404 pages by using a route with path='*', which catches all undefined routes and renders a custom NotFound component."
✅ Difference Between Stateless and Stateful Components in React
"A stateless component only relies on props and doesn't manage any internal data, while a stateful component holds and manages its own state, often using hooks like useState."
Stateless Component:
Stateful Component:
How to Handle Side Effects in React
In functional components, I use the useEffect hook to handle side effects like API calls, subscriptions, and manual DOM updates. I also use its cleanup function to prevent memory leaks
What is Redux, and how do you handle API calls in Redux?
✅ What is Redux?
Redux is a predictable state management library for JavaScript applications, often used with React.
- It stores application state in a centralized store.
- Components access state via
useSelectorand dispatch actions viauseDispatch. - The state updates through reducers in response to dispatched actions.
⚙️ Core Concepts of Redux:
- Store: Holds the entire state of the application.
- Actions: Plain objects that describe events (
{ type: 'INCREMENT' }). - Reducers: Pure functions that update the state based on actions.
- Dispatch: Sends actions to the reducer.
🌐 How to Handle API Calls in Redux
To handle asynchronous operations like API calls, you typically use middleware, such as:
- Redux Thunk (most common)
- Redux Toolkit (with built-in thunk support)
- Redux Saga (for more complex workflows)
🔧 Example with Redux Thunk:
- Dispatch in Component:
🧠 Interview Summary Line:
"Redux is a state management library that maintains a centralized store. I handle API calls using middleware like Redux Thunk, where I dispatch async actions to fetch data and update the state accordingly."
What is a closure, and how is it used?
✅ What is a Closure in JavaScript?
A closure is a function that remembers the variables from its lexical scope, even when the function is executed outside that scope.
🔍 In Simple Terms:
If an inner function accesses variables from an outer function, even after the outer function has finished executing, it's called a closure.
📦 Why Is It Useful?
Closures allow:
- Data encapsulation (private variables)
- Persistent state across function calls
- Callback functions with remembered context
🔧 Example:
Even though outer() has finished running, the inner() function still remembers count — this is a closure.
🧠 Interview Summary:
"A closure is when a function remembers the variables in its lexical scope even after the outer function has finished. It's used for things like data privacy, stateful functions, and maintaining access to variables across executions.
What is the difference between map and forEach methods?
map() returns a new array with transformed elements and is used when you need to store the result, while forEach() just iterates and is used for side effects like logging or DOM updates.
What is hoisting in JavaScript?
Hoisting is the behavior where variable and function declarations are moved to the top of their scope before execution. Unlike var, let and const are hoisted but not initialized, leading to a temporal dead zone
📌 Key Points:
- Variable and function declarations are hoisted.
- Only the declarations are hoisted, not initializations.
varis hoisted differently thanletandconst.
🔧 Example:
Internally, JavaScript interprets it like:
But with let or const:
What are semantic tags in HTML?
Semantic tags are HTML elements that clearly describe their meaning and purpose both to the browser and developers. They make the HTML structure more readable, accessible, and SEO-friendly.
Semantic tags like <header>, <nav>, <section>, and <footer> make HTML more meaningful, improve accessibility for screen readers, and help search engines better understand the page structure
What is an arrow function in JavaScript?
An arrow function is a shorter syntax for writing function expressions in JavaScript. It was introduced in ES6 and has a special behavior with the this keyword.
📌 Syntax:
🧠 Interview Summary Line:
"Arrow functions provide a concise syntax and do not have their ownthiscontext. They’re ideal for short callbacks and functions where lexicalthisbinding is preferred."
What is the event loop in JavaScript?
What Is the Event Loop in JavaScript?
The event loop is a mechanism in JavaScript that handles the execution of code, collects events, and processes tasks from the callback queue after the call stack is empty.
JavaScript is single-threaded, so it uses the event loop to manage non-blocking asynchronous tasks like setTimeout, API calls, and promises.
he event loop allows JavaScript to handle asynchronous operations by pushing callbacks from the queue to the call stack once it’s empty, enabling non-blocking execution in a single-threaded environment.
What is the difference between a development dependency and a regular
dependency?
Regular dependencies are needed to run the application in production, while development dependencies are only used during development for tools like testing, bundling, or linting
How They’re Defined in package.json:
Examples:
- Regular Dependencies (
dependencies): - React, Axios, Express — used in the actual application logic.
- Development Dependencies (
devDependencies): - Webpack, ESLint, Babel, Jest — used for building, testing, or formatting code during development.
What is debouncing, and how is it implemented?
What Is Debouncing?
Debouncing is a technique used to limit how often a function gets called. It ensures a function is only executed after a specified delay has passed since the last time it was invoked.
It’s commonly used for:
- Search input
- Resize or scroll events
- Button click prevention
🔧 How It Works:
- When the function is triggered multiple times (like while typing), it waits for a pause.
- If another trigger happens during the wait, the timer resets.
🛠️ Basic Debounce Implementation:
📌 Usage Example:
🧠 Interview Summary Line:
"Debouncing is a performance optimization technique that ensures a function is executed only after a certain delay of inactivity. It’s useful in scenarios like search input or resize events to prevent excessive function calls."
Write code to reverse your name spelling
Create a table component from an array of objects in React
Table Component (UserTable.jsx):
Usage in App:
Handle an API request from a component using fetch or Axios
How do you create a responsive web page?
I ensure responsiveness using the viewport meta tag, relative units, Flexbox/Grid layout, media queries, and by optimizing images. I may also use frameworks like Tailwind or Bootstrap to speed up developmen
Key Techniques to Create a Responsive Web Page:
- Use a Responsive Meta Tag:
This ensures the layout adjusts to the device's screen width.
- Use Relative Units (%, em, rem, vw, vh) Instead of Fixed px:
- Use Flexbox or Grid Layout:
- Media Queries for Breakpoints:
- Responsive Images:
- Frameworks (Optional but Helpful):
- Tailwind CSS – utility-first, responsive classes like
md:flex,sm:hidden. - Bootstrap – grid system with responsive breakpoints.
What is the difference between CSS and SASS?
CSS (Cascading Style Sheets)
- Standard styling language for web pages.
- Styles are written directly without any advanced features.
- No variables, nesting, or functions (vanilla CSS).
✅ SASS (Syntactically Awesome Style Sheets)
- A CSS preprocessor that extends CSS with powerful features.
- Requires a compiler (e.g.,
sassCLI or tools like Webpack). - Supports:
- Variables
- Nesting
- Mixins
- Functions
- Inheritance
How do you center a div with text on the page?
1. Using Flexbox (Modern and Recommended)
✅ 2. Using CSS Grid
✅ 3. Using Position + Transform
✅ Summary (for Interviews):
“I usually center content using Flexbox or Grid. Flexbox withjustify-contentandalign-itemsis very readable and responsive-friendly.”
What is event propagation?
Event propagation in JavaScript refers to the order in which events are handled in the DOM tree. It happens in three phases:
✅ Three Phases of Event Propagation:
- Capturing Phase (Capture/Bubbling down):
- The event starts from the window and travels down the DOM tree to the target element.
- Target Phase:
- The event reaches the target element (the one that was clicked or interacted with).
- Bubbling Phase:
- The event then bubbles up from the target back to the root (window).
✅ Example:
When the button is clicked, the logs will be:
— because bubbling is the default.
✅ To Use Capturing:
✅ Prevent Propagation:
- To stop bubbling or capturing:
📝 Summary (for interviews):
“Event propagation determines how events flow in the DOM: first capturing from root to target, then bubbling from target to root. We can control or stop propagation using stopPropagation().”Apply an animation using CSS.
Summary (for interviews):
“In CSS, animations are defined using@keyframes, and applied via theanimationproperty. You can animate properties like opacity, transform, color, etc., to enhance user experience.”
How do you maintain code quality?
I maintain code quality through a combination of peer code reviews, consistent styling with linting tools, automated unit tests, modular coding practices, proper version control, and CI/CD pipelines. I also prioritize performance, write good documentation, and refactor the code as necessary to keep it maintainable
Explain your strengths and weaknesses
My strengths include strong problem-solving skills, attention to detail, adaptability, and being a collaborative team player. On the other hand, I’ve recognized areas for improvement, such as managing perfectionism, delegating tasks effectively, overcoming public speaking anxiety, and avoiding overcommitment. I’m continuously working on improving these aspects to become a more effective professional.
What are your future plans?
"I aim to grow technically by mastering advanced React, Node.js, and state management. My long-term goal is to transition into a Senior Developer role, where I can contribute to team development and take on leadership responsibilities. Ultimately, I want to keep evolving as both a developer and a mentor."
What is the difference between shallow and mount in testing?
How does the useEffect hook work in functional components?
The useEffect hook in React allows you to handle side effects in functional components, such as data fetching, subscribing to external APIs, or manipulating the DOM. It replaces lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount in class components.
Key Points:
- Syntax:
- How it works:
- Without dependencies: The effect runs after every render.
- With an empty array (
[]): The effect runs once after the first render (component mount). - With specific dependencies: The effect runs when one of the dependencies in the array changes.
- Example:
- Cleaning up effects: If the effect involves subscriptions, timers, or any other side effects that need cleanup, you can return a cleanup function inside the
useEffect. This function will run either before the effect runs again or when the component unmounts. - Example:
Why it's useful:
- It provides a clean and simple way to handle side effects in functional components.
- It helps in reducing the need for class components, making the code more readable and concise.
When to use:
- Fetching data: Trigger API calls after the component mounts.
- DOM updates: Direct DOM manipulations like updating the scroll position.
- Timers/Intervals: Setting timeouts or intervals.
- Subscriptions: For WebSockets, event listeners, or other external sources.
How do you implement routing in a React application?
To implement routing in a React application, we use the react-router-dom library. This allows us to manage navigation between different views or pages without reloading the entire page, which is typical of a Single Page Application (SPA).
Steps to Implement Routing:
- Install
react-router-dom: - Install the library using npm or yarn:
- Set up Router in your
App.js: - You need to wrap your entire application in a
BrowserRouterto enable routing.
- Routing Components:
BrowserRouterwraps the app to manage history and the URL.Routespecifies the component that should render for a specific path.Switchensures that only the first matching route is rendered.Linkis used to navigate between routes without reloading the page.- Dynamic Routing:
- You can also define dynamic routes using route parameters:
- Redirects & Conditional Routing:
- You can use
Redirectfor redirecting users programmatically or conditionally render routes based on authentication."
