PREFACE
ABOUT THE BOOK
This book contains 200 very important React interview questions.
ABOUT THE AUTHOR
Happy Rawat has around 15 years of experience in software development. He helps candidates in clearing technical interview in tech companies.
Chapters
Fundamentals
1. React-Basics - I
2. React-Basics - II
3. Project Files & Folders
4. JSX
5. Components (Functional/Class)
6. Routing
Redux
16. Action/ Store/ Reducer
17. Core Principles/ Pros-Cons
18. Short Answer
19. Thunk/ Middleware/ Flux
Bonus
20. JS Essentials for React
21. Typescript
Hooks
7. useState/ useEffect
8. useContext/ useReducer
9. useCallback/ useMemo/…
10. Short Answer
Advance
11. LifeCycle Methods - I
12. LifeCycle Methods - II
13. Controlled Components
14. Code Splitting
15. React - Others
1: React-Basics - I
Q1. What is React? What is the Role of React in software development?
Q2. What are the Key Features of React?
Q3. What is DOM? What is the difference between HTML and DOM?
Q4. What is Virtual DOM? Difference between DOM and Virtual DOM?
Q5. What are React Components? What are the main elements of it?
Q6. What is SPA(Single Page Application)?
Q7. What are the 5 Advantages of React?
Q8. What are the Disadvantages of React?
Q9. What is the role of JSX in React? (3 points)
Q10. What is the difference between Declarative & Imperative syntax?
Q. What is React? What is the Role of React in software development?
React (library)/ Angular
(framework)
CSS, HTML & Javascript
(languages)
.NET(C#) / Spring(Java) / Laravel(PHP)
(framework)
C# / Java / PHP
(languages)
UI/ Client/ Frontendend
API Server/ Middleware
Database Server
SOL Server / Oracle
(RDBMS)
SQL
(languages)
Request
Response
Q. What is React? What is the Role of React in software development?
Q. What are the Key Features of React?
7 Key Features of React
1. Virtual DOM
2. Component Based Architecture
3. Reusability & Composition
4. JSX
(JavaScript XML)
5. Declarative Syntax
6. Community & Ecosystem
7. React Hooks
Q. What are the Key Features of React?
React utilizes a virtual representation of the DOM, allowing efficient updates by minimizing direct manipulation of the actual DOM, resulting in improved performance.
1. Virtual DOM:
React structures user interfaces as modular, reusable components, promoting a more maintainable and scalable approach to building applications.
2. Component-Based Architecture:
React enables the creation of reusable components that can be composed together, fostering a modular and efficient development process.
3. Reusability & Composition:
JSX is a syntax extension for JavaScript used in React, allowing developers to write HTML-like code within JavaScript, enhancing readability and maintainability.
4. JSX (JavaScript XML):
React have a declarative programming style(JSX), where developers focus on "what" the UI should look like and React handles the "how" behind the scenes. This simplify the code.
5. Declarative Syntax:
React benefits from a vibrant and extensive community, contributing to a rich ecosystem of libraries, tools, and resources, fostering collaborative development and innovation.
6. Community & Ecosystem:
Hooks are functions that enable functional components to manage state and lifecycle features, providing a more concise and expressive way to handle component logic.
7. React Hooks:
Q. What is DOM? What is the difference between HTML and DOM?
DOM Tree(Real)
Static HTML
Q. What is Virtual DOM? Difference between DOM and Virtual DOM?
DOM Tree(Real)
Virtual DOM
Reconciliation
(React Libraries)
Q. What is Virtual DOM? Difference between DOM and Virtual DOM?
DOM | Virtual DOM |
1. DOM is actual representation of the webpage. | Virtual DOM is lightweight copy of the DOM. |
2. Re-renders the entire page when updates occur. | Re-renders only the changed parts efficiently. |
3. Can be slower, especially with frequent updates. | Optimized for faster rendering. |
4. Suitable for static websites and simple applications | Ideal for dynamic and complex single-page applications with frequent updates |
Q. What are React Components? What are the main elements of it?
Q. What is SPA(Single Page Application)?
Q. What are the 5 Advantages of React?
1. Simple to build Single Page Application (by using Components)
2. React is cross platform and open source(Free to use)
3. Lightweight and very fast (Virtual DOM)
4. Large Community and Ecosystem
5. Testing is easy
Q. What are the Disadvantages of React?
Q. What is the role of JSX in React? (3 points)
Babel
Q. What is the difference between Declarative & Imperative syntax?
7 Key Features of React
1. Virtual DOM
2. Component Based Architecture
3. Reusability & Composition
4. JSX
(JavaScript XML)
5. Declarative Syntax
6. Community & Ecosystem
7. React Hooks
Q. What is the difference between Declarative & Imperative syntax?
2: React-Basics - II
Q1. What is Arrow Function Expression in JSX?
Q2. How to Setup React first project?
Q3. What are the Main Files in a React project?
Q4. How React App Load and display the components in browser?
Q5. What is the difference between React and Angular?
Q6. What are other 5 JS frameworks other than React?
Q7. Whether React is a Framework or a Library? What is the difference?
Q8. How React provides Reusability and Composition?
Q9. What are State, Stateless, Stateful and State Management terms?
Q10. What are Props n JSX?
Q. What is Arrow Function Expression in JSX?
=
Q. How to Setup React first project?
1. Install Node.js from below link:
https://nodejs.org/en/download
2. Install code editor (VS Code):
https://code.visualstudio.com/download
3. Create first React Project (Open VS Code -> Terminal -> New Terminal)
run command: “npx create-react-app my-app”
4. Open Project
Click File -> Open Project Folder “my-app”
5. Run Project
Open terminal(ctrl + ‘) key -> run “npm start”
Q. What are the Main Files in a React project?
Q. How React App Load and display the components in browser?
Request
Display
index.html
index.js
App.js
Single Page
Entry Point(JS)
Root Component
Comp1.js
Comp1.js
Comp1.js
Q. How React App load and display the components in browser?
ChildComponent.js
Custom child components placed over app component.
App.js
Root component which is the container of all the child components.
index.js
Replace root element of index.html file by App component
index.html
Single page which loads index.js by React libraries
Q. What is the difference between React and Angular?
React | Angular |
React and Angular both are used to create single page UI applications using components. | |
1. React is a JavaScript library | Angular is a complete framework. |
2. React uses a virtual DOM which makes it faster. | Angular uses a real DOM |
3. React is smaller in size and lightweight and therefore faster sometime. | Angular is bigger because it is a complete framework. |
4. React depends on external libraries for many complex features, so developer has to write many lines of code for complex functionalities. | Since Angular is a complete framework, therefore it provide built-in support for features like routing, forms, validation, and HTTP requests. |
5. React is simple to learn and more popular than Angular. | 5. Angular is slightly difficult to learn as it has Typescript, OOPS concept and many more thing. |
Q. What are other 5 JS frameworks other than React?
JS frameworks/ libraries
Angular
Vue.js
AngularJS
Backbone.js
Ember.js
Q. Whether React is a Framework or a Library? What is the difference?
Q. How React provides Reusability and Composition?
10
10
Q. What are State, Stateless, Stateful and State Management terms?
Q. What are Props n JSX?
3: React Project - Files & Folders
Q1. What is NPM? What is the role of node_modules folder?
Q2. What is the role of public folder in React?
Q3. What is the role of src folder in React?
Q4. What is the role of index.html page in React?
Q5. What is the role of index.js file and ReactDOM in React?
Q6. What is the role of App.js file in React?
Q7. What is the role of function and return inside App.js?
Q8. Can we have a function without a return inside App.js?
Q9. What is the role of export default inside App.js?
Q10. Does the file name and the component name must be same in React?
Q. What is NPM? What is the role of node_modules folder?
Q. What is the role of public folder in React?
Q. What is the role of src folder in React?
Q. What is the role of index.html page in React?
Q. What is the role of index.js file and ReactDOM in React?
Q. What is the role of App.js file in React?
Root Component (App.js)
Component 1
Component 2
Component 3
Component 4
Q. What is the role of App.js file in React?
Q. What is the role of function and return inside App.js?
Q. Can we have a function without a return inside App.js?
Q. What is the role of export default inside App.js?
Q. Does the file name and the component name must be same in React?
4: JSX
Q1. What is the role of JSX in React? (3 points)
Q2. What are the 5 Advantages of JSX?
Q3. What is Babel?
Q4. What is the role of Fragment in JSX?
Q5. What is Spread Operator in JSX?
Q6. What are the types of Conditional Rendering in JSX?
Q7. How do you iterate over a list in JSX? What is map() method?
Q8. Can a browser read a JSX File?
Q9. What is Transpiler? What is the difference between Compiler & Transpiler?
Q10. Is it possible to use JSX without React?
Q. What is the role of JSX in React? (3 points)
Babel
Q. What are the 5 Advantages of JSX?
Advantage of JSX
1. Improve code readability and writability
2. Error checking in advance(Type safety)
3. Support JavaScript expressions
4. Improved performance
5. Code reusability
Q. What is Babel?
Babel
Q. What is the role of Fragment in JSX?
Separate elements(Error)
Fragment (<>, <Fragment>)
Q. What is Spread Operator in JSX?
Q. What are the types of Conditional Rendering in JSX?
Conditional Rendering
1. If/else statements
2. Ternary operator
3. && operator
4. Switch statement
Q. How do you iterate over a list in JSX? What is map() method?
Q. Can a browser read a JSX File?
Q. What is Transpiler? What is the difference between Compiler & Transpiler?
Q. Is it possible to use JSX without React?
5: Components - Functional/ Class
Q1. What are React Components? What are the main elements of it?
Q2. What are the Types of React components? What are Functional Components?
Q3. How do you pass data between functional components in React?
Q4. What is Prop Drilling in React?
Q5. Why to Avoid Prop Drilling? In how many ways can avoid Prop Drilling?
Q6. What are Class Components In React?
Q7. How to pass data between class components in React?
Q8. What is the role of this keyword in class components?
Q9. What are the 5 differences btw Functional components & Class components?
Q. What are React Components? What are the main elements of it?
Q. What are the Types of React components? What are Functional Components?
Types of Components
1. Functional Components
2. Class Components
Q. How do you pass data between functional components in React?
Q. What is Prop Drilling in React?
Parent Component
Child Component
Gran Child Component
Q. Why to Avoid Prop Drilling? In how many ways can avoid Prop Drilling?
Root App
Parent 1
Parent 2
Child 1
Child 2
Data
Data
Data
Data
Root App
Parent 1
Parent 2
Child 1
Child 2
Data
Using Prop Drilling
Avoiding Prop Drilling
Q. Why to Avoid Prop Drilling? In how many ways can avoid Prop Drilling?
5 Ways to avoid Prop Drilling
1. Using Context API
2. Using Redux
3. Using Component Composition
4. Using Callback Functions
5. Using Custom Hooks
Q. What are Class Components In React?
Types of Components
1. Functional Components
2. Class Components
Q. How to pass data between class components in React?
Q. What is the role of this keyword in class components?
Q. What are the 5 differences btw Functional components & Class components?
Functional Component | Class Component |
1. Syntax: Defined as a JS function. | Defined as a JS(ES6) class. |
2. State: Originally stateless but can now maintain state using hooks. | Can manage local state with this.state. |
3. Lifecycle methods: No | Yes |
4. Readability: more readable & concise. | Verbose(complex). |
5. this keyword: No | Yes (Access props using this.props) |
6. Do not have render method. | Have render method. |
6: Routing
Q1. What is Routing and Router in React?
Q2. How to Implement Routing in React?
Q3. What are the roles of <Routes> & <Route> component in React Routing?
Q4. What are Route Parameters in React Routing?
Q5. What is the role of Switch Component in React Routing?
Q6. What is the role of exact prop in React Routing?
Q. What is Routing and Router in React?
Routing allows you to create a single-page web application with navigation, without the need for a full-page refresh.
Routing
React Router is a library for handling routing and enables navigation and rendering of different components based on the URL.
React Router
Q. How to Implement Routing in React?
Q. How to Implement Routing in React?
Step 1
Step 2
Step 3
Q. What are the roles of <Routes> & <Route> component in React Routing?
Q. What are Route Parameters in React Routing?
Q. What is the role of Switch Component in React Routing?
Q. What is the role of exact prop in React Routing?
7: Hooks -useState/ useEffect
Q1. What are React Hooks? What are the Top React Hooks?
Q2. What are State, Stateless, Stateful and State Management terms?
Q3. What is the role of useState() hook and how it works?
Q4. What is the role of useEffect(). How it works and what is its use?
Q5. What is Dependency Array in useEffect() hook?
Q6. What is the meaning of the empty array [] in the useEffect()?
Q. What are React Hooks? What are the Top React Hooks?
State
1. useState:
Side effects
2. useEffect:
Context
3. useContext:
Complex state
4. useReducer:
Memoization
5. useCallback:
Performance
6. useMemo:
Refs
7. useRef:
Synchronous Side effects.
8. useLayoutEffect:
Q. What are State, Stateless, Stateful and State Management terms?
Q. What is the role of useState() hook and how it works?
Q. What is the role of useState() hook and how it works?
Q. What is the role of useEffect(). How it works and what is its use?
2. Rendered after side effects by useEffect(eg: Loading data from external API)
Rendered initially
Q. What is the role of useEffect(). How it works and what is its use?
Browser Output
Q. What is Dependency Array in useEffect() hook?
Q. What is Dependency Array in useEffect() hook?
Q. What is the meaning of the empty array [] in the useEffect()?
8: Hooks - useContext/ useReducer
Q1. What is the role of useContext() hook?
Q2. What is createContext() method? What are Provider & Consumer properties?
Q3. When to use useContext() hook instead of props in real applications?
Q4. What are the similarities between useState() and useReducer() hook?
Q5. What is useReducer() hook? When to use useState() and when useReducer()?
Q6. What are the differences between useState() and useReducer() Hook?
Q7. What are dispatch & reducer function in useReducer Hook?
Q8. What is the purpose of passing initial state as an object in UseReducer?
Q. What is the role of useContext() hook?
Root App
Parent 1
Parent 2
Child 1
Child 2
Data
Data
Data
Data
Root App
Parent 1
Parent 2
Child 1
Child 2
Data
Using Prop Drilling
Avoiding Prop Drilling
Q. What is the role of useContext() hook?
Q. What is createContext() method? What are Provider & Consumer properties?
Q. When to use useContext() hook instead of props in real applications?
1. Theme Switching (Dark/ Light)
2. Localization (language selection)
3. Centralize Configuration Settings
4. User Preferences
5. Notification System
Component 1
Component 2
Component 3
Component 4
Component 1
Component 2
Q. What are the similarities between useState() and useReducer() hook?
Q. What are the similarities between useState() and useReducer() hook?
Q. What is useReducer() hook? When to use useState() and when useReducer()?
Q. What is useReducer() hook? When to use useState() and when useReducer()?
Q. What is useReducer() hook? When to use useState() and when useReducer()?
Component (Event Handler)
Dispatch
Reducer (Function)
Complex State Update
Component
Re-render
Q. What are the differences between useState() and useReducer() Hook?
useState | useReducer |
1. useState is simpler to use and used for managing simple state values. | useReducer is more appropriate for complex state logic or when the next state depends on the previous one. |
2. It is suitable for managing a single piece of state. | It is well-suited for managing multiple pieces of state that needs to be updated together. |
3. The useState hook takes an initial state as an argument and returns an array with two elements: the current state and a function to update the state. | The useReducer hook takes a reducer function and an initial state as arguments and returns the current state and a dispatch function. |
Q. What are dispatch & reducer function in useReducer Hook?
Q. What is the purpose of passing initial state as an object in UseReducer?
9: Hooks - useCallback/ useMemo/ useRef/ useLayoutEffect
Q1. What is the role of useCallback() hook in React?
Q2. What parameters does the useCallback hook accept & what does it returns?
Q3. What is the role of useMemo() Hook?
Q4. What is the role of useRef() Hook?
Q5. What is useLayoutEffect() Hook? Compare it with useEffect() hook.
Q6. When to use useLayoutEffect() Hook?
Q. What is the role of useCallback() hook in React?
Q. What parameters does the useCallback hook accept & what does it returns?
Q. What is the role of useMemo() Hook?
Q. What is the role of useRef() Hook?
Q. What is useLayoutEffect() Hook? Compare it with useEffect() hook.
Rendered after side effects by useEffect(eg: Loading data from external API)
Rendered initially
Q. What useLayoutEffect() Hook? Compare it with useEffect() hook.
Same Code
Q. What useLayoutEffect() Hook? Compare it with useEffect() hook.
useEffect
useEffect runs asynchronously and is scheduled after the UI has been rendered.
This means useEffect won't block the browser from updating the UI.
useLayoutEffect
useLayoutEffect run synchronously with the UI rendering.
This means useLayoutEffect can block the browser from updating the UI.
Q. When to use useLayoutEffect() Hook?
Q. When to use useLayoutEffect() Hook?
10: Hooks - Best Practices/ Short Answer
Q1. What are the Rules or Best Practices for hooks implementation?
Q2. What are Custom Hooks?
Q3. Tell 3 scenarios in which you can use useEffect() hook?
Q4. What useState() hook return in React?
Q5. How can you conditionally run effects with useEffect?
Q6. What problem do React Hooks solve?
Q7. What is the advantage of React Hooks over Lifecycle methods?
Q8. What is Context API?
Q9. What are the uses of all the Hooks in React?
Q. What are the Rules or Best Practices for hooks implementation?
Q. What are Custom Hooks?
Q. What useState() hook return in React?
1. StateVariable is the current state value.
1. stateUpdaterFunction is a function that used to update the state.
Q. Tell 3 scenarios in which you can use useEffect() hook?
useEffect() hook can be used for:
1. Fetching data from external API.
2. For managing subscriptions or event listeners.
3. For manual DOM manipulations.
4. For setting up timers or intervals.
Q. How can you conditionally run effects with useEffect?
Q. What problem do React Hooks solve?
Q. What is the advantage of React Hooks over Lifecycle methods?
Q. What is Context API?
Q. What are the uses of all the Hooks in React?
State
1. useState:
Side effects
2. useEffect:
Context
3. useContext:
Complex state
4. useReducer:
Memorize function
5. useCallback:
Memorize function result
6. useMemo:
Refs
7. useRef:
Synchronous Side effects.
8. useLayoutEffect:
Q. What are the uses of all the Hooks in React?
Used for adding state to functional components.
1. useState:
Enables performing side effects in functional components, such as data fetching.
2. useEffect:
Allows functional components to consume values from a React context.
3. useContext:
Provides an alternative to useState when the state logic is more complex.
4. useReducer:
Memoizes a callback function to prevent unnecessary re-renders of child components.
5. useCallback:
Memoizes the result of a function to optimize performance by avoiding unnecessary recalculations.
6. useMemo:
Creates a mutable object that persists across renders (used for interacting with DOM elements).
7. useRef:
Similar to useEffect but fires synchronously after all DOM mutations.
8. useLayoutEffect:
11: Components LifeCycle Methods - I
Q1. What are Component life cycle phases?
Q2. What are Component life cycle methods?
Q3. What are Constructors in class components? When to use them?
Q4. What is the role of super keyword in constructor?
Q5. What is the role of render() method in component life cycle?
Q6. How the State can be maintained in a class component?
Q7. What is the role of componentDidMount() method in component life cycle?
Q. What are Component life cycle phases?
Component Life Cycle Phases
1. Mounting Phase
(Component creation started)
2. Updating Phase
(Component updates)
3. Unmounting Phase
(Removal from the DOM )
Q. What are Component life cycle methods?
Component Life Cycle
Mounting Phase
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
Updating Phase
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
Unmounting Phase
componentWillUnmount()
Q. What are Constructors in class components? When to use them?
Component Life Cycle
Mounting Phase
constructor()
Updating Phase
Unmounting Phase
Q. What is the role of super keyword in constructor?
Q. What is the role of render() method in component life cycle?
Component Life Cycle
Mounting Phase
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
Updating Phase
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
Unmounting Phase
componentWillUnmount()
Q. What is the role of render() method in component life cycle?
Q. How the State can be maintained in a class component?
Q. What is the role of componentDidMount() method in component life cycle?
Component Life Cycle
Mounting Phase
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
Updating Phase
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
Unmounting Phase
componentWillUnmount()
Q. What is the role of componentDidMount() method in component life cycle?
2. Rendered after componentDidMount() to run Side effects(ex: loading data from external API) and then call render() method of updating phase again.
1. Rendered after constructor initialization.
Q. What is the role of componentDidMount() method in component life cycle?
12: Components LifeCycle Methods - II
Q1. What is the role of componentDidUpdate() method in component life cycle?
Q2. What is the role of componentWillUnmount() method in component life cycle?
Q3. How do you initialize state in a class component?
Q4. In which lifecycle phase component will be re-rendered?
Q5. What will happen if you don’t define a constructor in your React component?
Q6. Why we need class components when we already have functional components?
Q7. What are the 5 main methods of component lifecycle?
Q. What is the role of componentDidUpdate() method in component life cycle?
Component Life Cycle
Mounting Phase
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
Updating Phase
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
Unmounting Phase
componentWillUnmount()
Q. What is the role of componentDidUpdate() method in component life cycle?
2. Rendered after componentDidMount() Side effects.
1. Rendered after constructor initialization.
3. For any property or state change, componentDidUpdate() method will refetch the data and re-rendered in the DOM.
Q. What is the role of componentDidUpdate() method in component life cycle?
Q. What is the role of componentWillUnmount() method in component life cycle?
Component Life Cycle
Mounting Phase
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
Updating Phase
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
Unmounting Phase
componentWillUnmount()
Q. What is the role of componentWillUnmount() method in component life cycle?
2. Rendered after componentDidMount().
1. Rendered after constructor() initialization.
3. Re-rendered after, componentDidUpdate() on any state or property change.
3. Before unmounting of component, componentWillUnmount() will do the cleanup task.
Q. What is the role of componentWillUnmount() method in component life cycle?
Q. How do you initialize state in a class component?
Q. In which lifecycle phase component will be re-rendered?
Component Life Cycle Phases
1. Mounting Phase
(Component creation started)
2. Updating Phase
(Component updates)
3. Unmounting Phase
(Removal from the DOM )
Q. What will happen if you don’t define a constructor in your React component?
Q. Why we need class components when we already have functional components?
Q. What are the 5 main methods of component lifecycle?
Component Life Cycle Main Methods
1. constructor()
2. render()
3. componentDidMount()
4. componentDidUpdate()
5. componentWillUnmount()
Q. What are the 5 main methods of component lifecycle?
Initializes the component's state and automatically called when the component is being created.
1. constructor()
Returns UI elements based on the current state and props;
2. render()
Invoked after the component has been added to the DOM; used for data fetching and subscribing to external data sources.
3. componentDidMount()
Invoked after a component's state or props have been updated and it has been re-rendered; used for handling side effects after updates.
4. componentDidUpdate()
Called just before a component is unmounted and removed from the DOM; used for cleanup tasks and releasing resources.
5. componentWillUnmount()
13: Controlled & Uncontrolled Components
Q1. What are Controlled Components in React?
Q2. What are the Differences btw Controlled & Uncontrolled Components?
Q3. What are characteristics of controlled components?
Q4. What are the advantages of using controlled components in React forms?
Q5. How to handle forms in React?
Q6. How can you handle multiple input fields in a controlled form?
Q7. How do you handle form validation in a controlled component?
Q8. In what scenarios might using uncontrolled components be advantageous?
Q. What are Controlled Components in React?
Q. What are the Differences btw Controlled & Uncontrolled Components?
Q. What are the Differences btw Controlled & Uncontrolled Components?
Controlled Components | Uncontrolled Components |
1. Values are controlled by React state. | Values are not controlled by React state. |
2. Event handlers update React state. | No explicit state update; values can be accessed directly from the DOM. |
3. Don’t depend on useRef(). | Commonly uses useRef() to access form element values. |
4. Re-renders on state changes. | Less re-rendering since values are not directly tied to React state. |
5. A recommended and standard practice for form handling in React. | Useful in certain scenarios but less commonly considered a best practice. |
Q. What are characteristics of controlled components?
Q. What are the advantages of using controlled components in React forms?
Q. How to handle forms in React?
Q. How can you handle multiple input fields in a controlled form?
Q. How do you handle form validation in a controlled component?
Q. In what scenarios might using uncontrolled components be advantageous?
14: Code Splitting
Q1. What is Code Splitting in React?
Q2. How to Implement Code Splitting in React?
Q3. What is the role of Lazy and Suspense methods in React?
Q4. What are the Pros and Cons of Code Splitting?
Q5. What is the role of the import() function in code splitting?
Q6. What is the purpose of the fallback prop in Suspense?
Q7. Can you dynamically load CSS files using code splitting in React?
Q8. How do you inspect and analyze the generated chunks in a React application?
Q. What is Code Splitting in React?
Bundle project files
.css
.png
.sass
.js
.css
.png
.sass
.js
With Code Splitting Implemented
All in one Request
Each chunk Loaded on demand
Without Code Splitting
Q. How to Implement Code Splitting in React?
Q. How to Implement Code Splitting in React?
Q. What is the role of Lazy and Suspense methods in React?
Q. What are the Pros and Cons of Code Splitting?
5 Pros of Code Splitting:
1. Faster Initial Load Time:
Code splitting reduces the initial load time of your application by only loading the necessary code for the current view or feature. Good for performance.
2. Optimized Bandwidth Usage:
By loading only, the code needed for a specific page, it reduces the amount of data transferred over the network. Good for slow network.
3. Improved Caching:
Smaller, more focused code chunks are more likely to be cached by the browser.
4. Parallel Loading:
Multiple smaller chunks can be loaded simultaneously, leading to faster overall loading times.
5. Easier Maintenance:
Code splitting can make your codebase more modular, independent and easier to maintain.
Q. What are the Pros and Cons of Code Splitting?
5 Cons of Code Splitting:
1. Complexity:
Implementing code splitting introduces additional complexity to your application. This complexity can make the development process slow.
2. Tooling Dependencies:
Proper code splitting often requires specific build tools and configurations, such as Webpack and Babel. Managing these tools is challenging.
3. Potential for Runtime Errors:
Dynamically loading code at runtime can introduce the possibility of runtime errors. Careful testing is necessary to catch such issues.
4. Increased Number of Requests:
Code splitting may increase the number of HTTP requests needed to fetch all the necessary chunks. This can impact performance.
5. Learning Curve:
Developers who are new to code splitting may need time to understand the concepts and best practices. This can be a challenging.
Q. What is the role of the import() function in code splitting?
Q. What is the purpose of the fallback prop in Suspense?
Q. Can you dynamically load CSS files using code splitting in React?
Q. How do you inspect and analyze the generated chunks in a React application?
15: React - Others
Q1. What is a Higher-Order Component in React?
Q2. What are the 5 ways to Style React components? Explain Inline Styles?
Q3. What are the differences between React & React Native?
Q4. What is GraphQL?
Q5. What are the Top 3 ways to achieve state management? When to use what in React?
Q6. How can you Implement Authentication in a React application?
Q7. What is the use of React Profiler?
Q8. What is the difference between fetch & axios for api calls in React?
Q9. What are the popular Testing Libraries for React?
Q10. How can you Optimize Performance in a React application?
Q11. Explain Reactive Programming with example?
Q12. In how many ways can we implement Reactive Programming in React?
Q13. How to pass data from child component to parent Component in React?
Q. What is a Higher-Order Component in React?
Q. What are the 5 ways to Style React components? Explain Inline Styles?
5 ways to Style React components
1. Inline Styles
2. CSS Stylesheets
3. CSS-Modules
4. Global Stylesheets
5. CSS Frameworks
Q. What are the differences between React & React Native?
React | React Native |
1. React is a library | React Native is a framework. |
2. React is used for building web interfaces. | React Native is used for building mobile applications. |
3. Run on Web browsers. | Run on iOS and Android platforms. |
4. HTML and CSS are used for UI. | Native UI components (e.g., View, Text) are used for UI. |
5. Deployed as web applications. | Deployed through app stores(e.g., App Store, Google Play). |
Q. What is GraphQL?
Q. What are the Top 3 ways to achieve state management? When to use what in React?
1. useState Hook:
2. Context API:
3. Redux:
Q. How can you Implement Authentication in a React application?
Front-end/ Client-side
Middleware/ Server-side/ Backend
1. POST: {username, password}
2. Authenticate &
create JWT Token
3. Return Response {JWT token}
4. Store JWT token at local storage
5. Request Data {JWT token: Header}
7. Send Data
6. Validate token signature
8. Display data on browser
Q. What is the use of React Profiler?
Q. What is the difference between fetch & axios for api calls in React?
Q. What are the popular Testing Libraries for React?
Testing Libraries in React
Jest
React Testing Library
Enzyme
Cypress
Q. How can you Optimize Performance in a React application?
1. Memoization with useMemo and useCallback:
2. Optimizing Renders with React.Fragment:
3. Lazy Loading with React.lazy:
4. Code Splitting:
5. Optimizing Images and Assets
Q. How can you Optimize Performance in a React application?
Use this hooks to memoize values and, reducing unnecessary recalculations.
1. Memoization with useMemo and useCallback:
Use it to avoid unnecessary wrapper elements that could cause additional DOM nodes.
2. Optimizing Renders with React.Fragment:
Use it to load components lazily, reducing the initial bundle size and improving initial loading performance.
3. Lazy Loading with React.lazy:
Employ code splitting to divide your application into smaller chunks that are loaded on demand, improving initial load times.
4. Code Splitting:
Compress and optimize images, use responsive images, and leverage lazy loading for images to reduce network and rendering overhead.
5. Optimizing Images and Assets:
Q. Explain Reactive Programming with example?
Live Search Suggestion
Q. In how many ways can we implement Reactive Programming in React?
Reacting to changes in local component state and passing data reactively through props.
1. State and Props
Leveraging useState and useEffect hooks for managing state and side effects in functional components.
2. React Hooks:
Reacting to user interactions through event handling and updating state accordingly.
3. Event Handling:
Sharing and managing global state reactively across components using the Context API.
4. Context API:
Using state management libraries like Redux for managing complex application state reactively.
5. Redux:
Using class components and lifecycle methods for handling side effects and updates.
6. Component Lifecycle Methods:
Utilizing async/await syntax for handling asynchronous operations reactively.
7. Async/Await:
Leveraging RxJS for handling asynchronous operations and data streams in a reactive manner.
8. RxJS and Observables:
Q. How to pass data from child component to parent Component in React?
16: Redux - Component/ Action/ Store/ Reducer
Q1. What is the role of Redux in React?
Q2. When to use Hooks and when to use Redux in React applications?
Q3. What is the Flow of data in React while using Redux?
Q4. How to install Redux for React application?
Q5. What are Action Creators in React Redux?
Q6. Difference between Action Creators, Action Object & Action Type?
Q7. Explain React Component Structure while using Redux?
Q8. What is the role of Store in React Redux?
Q9. What is the role of Reducer in Redux?
Q. What is the role of Redux in React?
Store
(Centralize state)
Component1
Component2
Component3
Component4
Dispatcher
Dispatcher
Dispatcher
Dispatcher
Action
Reducer
Action
Action
Action
Q. When to use Hooks and when to use Redux in React applications?
Q. What is the Flow of data in React while using Redux?
Component
(Component.js)
Action Creators
(action.js)
Store
(store.js)
Reducer
(reducer.js)
Interaction (click, mouse etc.)
Action Dispatch
(Component.js)
(Previous state, action)
(New/ Current state)
(Current state)
Q. How to install Redux for React application?
(run this command):
Q. What are Action Creators in React Redux?
Q. Difference between Action Creators, Action Object & Action Type?
Q. Explain React Component Structure while using Redux?
Component
(Component.js)
Action Creators
(action.js)
Store
(store.js)
Reducer
(reducer.js)
Interaction (click, mouse etc.)
Action Dispatch
(Component.js)
(Previous state, action)
(New state)
(Current state)
Q. Explain React Component Structure while using Redux?
Q. Explain React Component Structure while using Redux?
Q. What is the role of Store in React Redux?
Component
(Component.js)
Action Creators
(action.js)
Store
(store.js)
Reducer
(reducer.js)
Interaction (click, mouse etc.)
Action Dispatch
(Component.js)
(Previous state, action)
(New state)
(Current state)
Q. What is the role of Reducer in Redux?
Store
(store.js)
Reducer
(reducer.js)
(Previous state, action)
(New state)
17: Redux - Core Principles/ Pros-Cons/ Local & Redux State
Q1. Explain the Core Principles of Redux?
Q2. List 5 benefits of using Redux in React?
Q3. What are the differences between local component state & Redux state?
Q4. What are the challenges or disadvantages while using Redux?
Q. Explain the Core Principles of Redux?
1. Single Source of Truth (Store)
2. State is Read-Only (Unidirectional)
3. Changes using Pure Functions (Reducers)
4. Actions Trigger State Changes (Actions)
5. Predictable State Changes (Actions)
Component
(Component.js)
Action Creators
(action.js)
Store
(store.js)
Reducer
(reducer.js)
Interaction (click, mouse etc.)
(Previous state, action)
(Current state)
Q. Explain the Core Principles of Redux?
The entire application state is stored in one place, simplifying data management and ensuring a consistent view of the application.
1. Single Source of Truth:
State cannot be directly modified. To make changes to the state, you need to dispatch an action. This ensures that the state transitions are explicit and traceable.
2. State is Read-Only:
This ensures predictability and consistency because pure functions returns the same result if the same arguments are passed.
3. Changes using Pure Functions (Reducers):
Plain JavaScript objects (actions) describe state changes, guiding the store to invoke reducers and update the application state accordingly.
4. Actions Trigger State Changes:
State changes are determined by actions, fostering a predictable flow of data and simplifying debugging in response to specific actions.
5. Predictable State Changes with Actions:
Q. List 5 benefits of using Redux in React?
The application state is stored in a single, predictable and centralize source (the store).
1. Predictability & Centralization:
For larger application, Redux is a structured and scalable approach for managing state.
2. Maintainability:
Redux has powerful developer tools that make it easier to trace and debug state changes.
3. Debuggability:
Redux can be used with various JavaScript frameworks and libraries.
4. Interoperability:
Redux has a large and active community, resulting in a rich ecosystem of tools and extensions.
5. Community & Ecosystem:
Q. What are the differences between local component state & Redux state?
Local Component State | Redux State |
1. Scope: Limited to the component where defined. | Global and accessible across components. |
2. Management: Managed internally by the component. | Managed externally by the Redux store. |
3. Performance: Generally, more performant for small-scale applications. | More performant for large applications. |
4. Complexity: Simpler to set up and manage. | Comparatively complex to manage. |
5. Testing: Simpler to test with component-specific state. | Requires more comprehensive testing due to global nature and interactions between components. |
Q. What are the challenges or disadvantages while using Redux?
1. Boilerplate Code
2. Learning Curve
3. Verbosity and Complexity
4. Overhead for Small Projects
5. Global State for Local Components
6. Integration with Non-React Libraries
Q. What are the challenges or disadvantages while using Redux?
Implementing Redux requires writing extensive boilerplate code in action, reducer, store, increasing code volume and complexity.
1. Boilerplate Code:
Understanding Redux concepts can be challenging, posing a learning curve for developers, especially those new to React state management.
2. Learning Curve:
As projects grow, Redux code may become verbose and complex, demanding careful management of actions and reducers.
3. Verbosity and Complexity:
In small projects, Redux may introduce unnecessary complexity, potentially outweighing its benefits in development efficiency.
4. Overhead for Small Projects:
Overusing Redux for local state introduces unnecessary complexity, as not all state requires a global scope.
5. Global State for Local Components:
Integrating Redux with non-React libraries or frameworks may demand additional effort and customization, potentially adding complexity to the project.
6. Integration with Non-React Libraries:
18: Redux - Short Answer
Q1. What is Provider Component? How components getting the state from Redux store?
Q2. What is the role of Connect function in React-Redux?
Q3. What are the 4 Important Files in React-Redux project?
Q4. How to structure the project and maintain state in multiple components?
Q5. Explain the concept of immutability in the context of Redux?
Q6. Which are the typical properties of an Action object in React-Redux project?
Q7. Difference btw mapDispatchToProps & mapStateToProps in the connect?
Q8. What is the meaning of Unidirectional Data Flow in Redux?
Q9. How does Redux handle communication between components?
Q10. What is Payload property in Redux?
Q. What is Provider Component? How components getting the state from Redux store?
Q. What is the role of Connect function in React-Redux?
Q. What are the 4 Important Files in React-Redux project?
src/
|-- actions.js
|-- reducer.js
|-- store.js
|-- CounterComponent.js
|-- App.js
|-- index.js
Q. How to structure the project and maintain state in multiple components?
src/
|-- actions/
| |-- counterActions.js
| |-- userActions.js
|
|-- reducers/
| |-- counterReducer.js
| |-- userReducer.js
|
|-- store/
| |-- configureStore.js
|
|-- components/
| |-- CounterComponent.js
| |-- UserComponent.js
|
|-- App.js
|-- index.js
Root Component(App.js)
CounterComponent
src/
|-- actions.js
|-- reducer.js
|-- store.js
|-- CounterComponent.js
|-- App.js
|-- index.js
Root Component(App.js)
CounterComponent
UserComponent
Q. Explain the concept of immutability in the context of Redux?
Q. Which are the typical properties of an Action object in React-Redux project?
Q. Difference btw mapDispatchToProps & mapStateToProps in the connect?
Q. What is the meaning of Unidirectional Data Flow in Redux?
Component
(Component.js)
Action Creators
(action.js)
Store
(store.js)
Reducer
(reducer.js)
Interaction (click, mouse etc.)
Action Dispatch
(Component.js)
(Previous state, action)
(New state)
(Current state)
Q. How does Redux handle communication between components?
Store
(Centralize state)
Component1
Component2
Component3
Component4
Dispatcher
Dispatcher
Dispatcher
Dispatcher
Action
Reducer
Action
Action
Action
Q. What is Payload property in Redux?
19: Redux - Thunk/ Middleware/ Error Handling/ Flux
Q1. What is the difference between Regular Action creator & Thunk action creator?
Q2. Explain the concept of Middleware in React-Redux?
Q3. How can you handle Asynchronous Operations & side-effect in React-Redux?
Q4. How does Error Handling work in Redux?
Q5. What is the difference between Flux & Redux?
Q. What is the difference between Regular Action creator & Thunk action creator?
Q. Explain the concept of Middleware in React-Redux?
Component
(Component.js)
Action Creators
(action.js)
Store
(store.js)
Reducer
(reducer.js)
Interaction (click, mouse etc.)
Action Dispatch
(Component.js)
(Previous state, action)
(New state)
(Current state)
Middleware
API
Q. How can you handle Asynchronous Operations & side-effect in React-Redux?
Q. How does Error Handling work in Redux?
Q. What is the difference between Flux & Redux?
20: JavaScript Essentials for React
Q1. What are Variables? What is the difference between var, let, and const ?
Q2. What are the Types of Conditions statements in JS?
Q3. What is Error Handling in JS?
Q4. What is the difference between Spread and Rest operator in JS?
Q5. What are Arrays in JS? How to get, add & remove elements from arrays?
Q6. What is Array Destructuring in JS?
Q7. What are Functions in JS? What are the types of function?
Q8. Difference between Named and Anonymous functions? When to use what?
Q9. What is Function Expression in JS?
Q10. What are Arrow Functions in JS? What is it use?
Q11. What are Callback Functions? What is it use?
Q12. What is Higher-order function In JS?
Q13. What are Pure and Impure functions in JS?
20: JavaScript Essentials for React
Q14. What are template literals and string interpolation in strings?
Q15. What are Objects in JS?
Q16. What is the difference between an array and an object?
Q17. How do you add or modify or delete properties of an object?
Q18. What is asynchronous programming in JS? What is its use?
Q19. What is the difference between synchronous and asynchronous programming?
Q20. What are Promises in JavaScript?
Q21. How to implement Promises in JavaScript?
Q22. What is the purpose of async/ await? Compare it with Promises?
Q23. What are Classes in JS?
Q24. What is a Constructor?
Q25. What is the use of this keyword?
Q. What are variables? What is the difference between var, let, and const ?
Q. What are variables? What is the difference between var, let, and const ?
Q. What are the types of conditions statements in JS?
Q. What are the types of conditions statements in JS?
Types of condition statements
1. If/ else statements
2. Ternary operator
3. Switch statement
Q. What is Error Handling in JS?
Q. What is the difference between Spread and Rest operator in JS?
Uses of Spread Operator
Copying an Array
Merging Arrays
Passing Multiple Arguments to a Function
Q. What is the difference between Spread and Rest operator in JS?
Q. What are Arrays in JS? How to get, add & remove elements from arrays?
Multiple
Variables
Array1
Array2
Array3
Array4
Q. What are Arrays in JS? How to get, add & remove elements from arrays?
Arrays methods
Get
indexOf()
find()
filter()
Slice()
Add
push()
concat()
Remove
pop()
shift()
splice()
Modify
map()
forEach()
Others
join()
length
sort()
reverse()
reduce()
some()
every()
Q. What are Arrays in JS? How to get, add & remove elements from arrays?
Q. What is Array Destructuring in JS?
Multiple
Variables
Array1
Array2
Array3
Array4
Structuring
Destructuring
Q. What is Array Destructuring in JS?
Q. What are Functions in JS? What are the types of function?
Function keyword
Function name
Parameters list
Function body
Function call
Argument list
Q. What are Functions in JS? What are the types of function?
Types of Functions
Named Function
Anonymous Function
Function Expression
Arrow Function
IIFE
Callback Function
Higher-Order Function
Q. What is the difference between named and anonymous functions? � When to use what in applications?
Q. What is function expression in JS?
Q. What are Arrow Functions in JS? What is it use?
Parameters list
Function body
Q. What are Callback Functions? What is it use?
Callback function
Higher-order function
Q. What is Higher-order function In JS?
Callback function
High-order function
Q. What are Pure and Impure functions in JS?
Q. What are template literals and string interpolation in strings?
Q. What are Objects in JS?
Q. What are Objects in JS?
Object
String/ number/ boolean/ null/ undefined
Array
Function
Object
Q. What is the difference between an array and an object?
Q. How do you add or modify or delete properties of an object?
Q. What is asynchronous programming in JS? What is its use?
Q. What is asynchronous programming in JS? What is its use?
Use of Asynchronous Operations
Fetching Data from API
Downloading Files
Uploading Files
Animations and Transitions
Time taking operations…
Q. What is the difference between synchronous and asynchronous programming?
Q. What are Promises in JavaScript?
Q. How to implement Promises in JavaScript?
resolve()
reject()
Q. How to implement Promises in JavaScript?
Q. Explain the use of async and await keywords in JS?
Q. What are Classes in JS?
Q. What is a constructor?
Q. What is the use of this keyword?
21: Typescript
Q1. What is Typescript? Or What is the difference between Typescript and Javascript?
Q2. How to install Typescript and check version?
Q3. What is the difference between let and var keyword?
Q4. What is Type annotation?
Q5. What are Built in/ Primitive and User-Defined/ Non-primitive Types in Typescript?
Q6. What is “any” type in Typescript?
Q7. What is Enum type in Typescript?
Q8. What is the difference between void and never types in Typescript?
Q9. What is Type Assertion in Typescript?
Q10. What are Arrow Functions in Typescript?
21: Typescript
Q11. What is Object Oriented Programming in Typescript?
Q12. What are Classes and Objects in Typescript?
Q13. What is Constructor?
Q14. What are Access Modifiers in Typescript?
Q15. What is Encapsulation in Typescript?
Q16. What is Inheritance in Typescript?
Q17. What is Polymorphism in Typescript?
Q18. What is Interface in Typescript?
Q19. What's the difference between extends and implements in TypeScript ?
Q20. Is Multiple Inheritance possible in Typescript?
Q55. What is Typescript? Or What is the difference between Typescript and Javascript?
What is Typescript? What are the advantages of Typescript over Javascript?
Q55
Q56. How to install Typescript and check version?
How to install Typescript and check version?
Q56
Q57. What is the difference between let and var keyword?
What is the difference between let and var keyword?
Q57
Compile time error, since let variable “i” scope is only limited inside for loop.
No error, since var variable “j” scope is not limited inside for loop, but inside the whole function fnLetVar().
Q58. What is Type annotation?
What is Type annotation in Typescript?
Q58
For example, in below image when we set variable “i” as number. And now if you assign “i” a string or Boolean value, then Typescript will show the compile time error, which is good.
Q59. What are Built in/ Primitive and User-Defined/ Non-primitive Types in Typescript?
What are Built in/ Primitive and User-Defined/ Non-primitive Types in Typescript?
Q59
Q60. What is “any” type in Typescript?
What is “any” type in Typescript?
Q60
For example, see in the image there is no compile time error for assigning different types to variable “x” because it is of any type.
Q61. What is Enum type in Typescript?
What is Enum type in Typescript?
Q61
Suppose you have a family of constants(Directions) like this in image.
Now if you want to insert some direction, for example SouthWest between 1 and 2, then it will be a problem, as you have to change this in all of your application.
So here enum is a better way as you don’t have to assign the numbers then.
Q62. What is the difference between void and never types in Typescript?
What is the difference between void and never types in Typescript?
Q62
In image, fnVoid() function will return empty.
For example, in image fnNever function which will not reach to its last line, and it always throws an exception.
Q63. What is Type Assertion in Typescript?
What is Type Assertion in Typescript?
Q63
For example, in below image, if we do not put <String>, then typescript will try to assume the type of “secondname” by itself automatically.
But by putting <String>, we are asserting and informing the compiler about the type of secondName as String and now compiler will not do automatic typechecking.
Q64. What are Arrow Functions in Typescript?
What are Arrow Functions in Typescript?
Q64
In below image, you can see how the same function can be written using arrow function.
Q65. What is Object Oriented Programming in Typescript?
What is Object Oriented Programming(OOPS) in Typescript?
Q65
In the image, you can see the concepts used in object oriented programming.
OOPS
Classes & Objects
Encapsulation
(Data Security)
Inheritance
(Code Reusability)
Polymorphism
(Multiple Forms)
Abstraction
(Hide Complexity)
Q66. What are Classes and Objects in Typescript?
What are Classes and Objects in Typescript?
Q66
Person is a class with two properties(name, age) and one method(familyCount)
objPerson is the object/instance of Person class. By this object only we can set Person class properties and call the method of the class.
Q67. What is Constructor?
What is a Constructor in Angular?
Q67
Q68. What are Access Modifiers in Typescript?
What are Access Modifiers in Typescript?
Q68
Access Modifiers
public
private
protected
What are Access Modifiers in Typescript?
Q69
1. empId no error, as it is public.
2. empName error, as it is out of the class and it is private.
3. empAge error, as it is out of the class and it is protected.
3. But in PermanentEmployee empAge no error, because it is inside the derived class(PermanentEmployee) of Employee.
Q69. What is Encapsulation in Typescript?
What is Encapsulation in Typescript?
Q70
For example, here in code _empId is the data. We can make it public and then it can be accessible outside the Employee class.
But as per OOPS concept encapsulation this is wrong as it can lead to data security issues.
Therefore, we should mark this _empId data as private. And then create a function(getEmpId), which will help in accessing this _empId outside of this class.
Outside the class, in the last line we are calling getEmpId method to access/dispaly the data _empId.
This is good for data security to prevent direct data access.
Q70. What is Inheritance in Typescript?
What is Inheritance in Typescript?
Q71
Animal |
Eat() |
Sleep() |
Dog |
Bark() |
Cat |
Meaow() |
Base/ Parent/ Super Class
Derived/ Child/ Sub Class
For example, in the image Dog and Cat class are derived from Animal base class.
Therefore, Eat() and Sleep() methods of Animal base class will be automatically available inside Dog and Cat derived class without even writing it.
Inheritance is good for reusability of code. As you can write one method in base class, and then use it in multiple derived classes.
What is Inheritance in Typescript?
Q71
Both Eat() and Bark() method are accessible via Dog class object. Eat is from the base class but.
Q71. What is Polymorphism in Typescript?
What is Polymorphism in Typescript?
Q72
Father |
GetName() |
GetSurName() |
Son |
GetName() |
Base/ Parent/ Super Class
Derived/ Child/ Sub Class
For example, in the image Son can inherit the GetSurName() method implementation of father. But the GetName() method implementation should be different for son. So son can have a different implementation but the method name can be same as GetName().
Like in dictionary, a word “Running” can have multiple meanings: Running a race or Running a computer.
Similarly in programming, Polymorphism can be used to do multiple things with the same name.
What is Polymorphism in Typescript?
Q72
GetName() method of Father class object output is different, and Getname() method of Son class object output is different. Same name method taking multiple forms.
Q72. What is Interface in Typescript?
What is Interface and why to use them in Typescript?
Q72
For example, we have multiple classes PermanentEmployee, ContractEmployee etc.
They all must have the Role() method, but the body of Role() method can be different.
Now to maintain consistency we will create the Interface IEmployee, with just declaration of Role() method and implement this interface in all the classes.
This will make sure all the Employees classes are in sync with the Role method. It will also help in unit testing.
Q73. What's the difference between extends and implements in TypeScript
What's the difference between extends and implements?
Q73
Q74. Is Multiple Inheritance possible in Typescript?
Is Multiple Inheritance possible in Typescript?
Q74
See in first image there is the compile time error in Employee2 as multiple base classes are not allowed, but in second image with multiple interfaces iit is working.