0% found this document useful (0 votes)
22 views

React JS Interview Qusestions

Uploaded by

karan tomar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

React JS Interview Qusestions

Uploaded by

karan tomar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

React JS Interview Qusestions

1. What is ReactJS?
Open-source, component-based front-end JavaScript library.

Developed by Facebook.

Primarily used for the view layer of web applications.

Utilizes a virtual DOM for efficient updating.

Applications are composed of small, reusable components.

Components can manage internal states for dynamic behaviors.

2. Benefits of ReactJS:
Easy to learn:

ReactJS is a JavaScript library that is simple to understand for developers


familiar with JS.

Reusable Components:

Components can be reused across the application, enhancing


development speed and efficiency.

Virtual DOM:

Enables faster updates by rendering changes in a virtual environment


before applying them to the actual DOM.

Flux and Redux architecture:

Supports unidirectional data flow, which improves state management.

SEO-Friendly:

Faster rendering, which can improve SEO rankings.

Developer Tools:

Chrome and Firefox dev extensions to inspect component hierarchies.

Performance Enhancement:

React JS Interview Qusestions 1


Virtual DOM provides significant performance improvements for large-
scale applications.

Scope for Code Testing:

Easy testing and debugging of React applications.

3. What is Create React App?


Standard app generator for React, developed by Facebook.

Key features:

ES6 and JSX transpilation.

Dev server with hot module reloading.

Code linting.

CSS auto-prefixing.

Jest testing integration.

4. Features of ReactJS:
Virtual DOM: React creates an in-memory representation of the real DOM,
leading to faster UI updates.

JSX: Syntax extension that allows HTML-like code in JavaScript files.

Simplicity: Component-based structure makes code easier to manage and


understand.

One-way Data Binding: Data flows from parent to child components, ensuring
controlled state management.

React Native: A version of React for building native mobile applications.

5. Disadvantages of ReactJS:
Dynamic Technology: Constant updates require continuous learning.

Average Documentation: Frequent updates make it hard to maintain


comprehensive documentation.

React JS Interview Qusestions 2


JSX as a barrier: Some developers find JSX's combination of HTML and
JavaScript difficult to adopt.

View Part Only: ReactJS focuses solely on the UI layer, requiring additional
libraries for full-stack development.

6. How to Install ReactJS?


Include the React library (react.js) and React DOM library (react-dom.js) in
your HTML.

Use npm or Yarn for installation:

npm install --save react react-dom

yarn add react react-dom

7. Difference between ReactJS and AngularJS:


ReactJS:

Developed by Facebook.

One-way data binding.

Uses Virtual DOM.

Focuses on view rendering (library).

AngularJS:

Developed by Google.

Two-way data binding.

Uses browser's actual DOM.

Full MVC framework for building large-scale applications.

8. Difference between ReactJS and React Native:


ReactJS:

Library for building web applications.

Uses virtual DOM for rendering.

React JS Interview Qusestions 3


React Native:

Framework for building mobile applications.

Uses native components for rendering.

9. Which browsers does ReactJS support?


Supports all modern browsers (Google Chrome, Firefox, Microsoft Edge).

Does not support older browsers like Internet Explorer without ES5 polyfills.

10. What is JSX in React?


JavaScript XML, a syntax extension that combines HTML-like tags with
JavaScript logic.

Syntactic sugar for React.createElement .

11. Benefits of using JSX in React:


Faster due to optimization during compilation.

Type-safe.

Easier to write templates for those familiar with HTML.

12. Difference between DOM and Virtual DOM:


DOM: HTML-based structure that represents elements in the document.

Virtual DOM: A lightweight in-memory version of the real DOM, which


improves performance by reducing direct DOM manipulation.

13. What is the use of keys in ReactJS?


Used to uniquely identify elements in a list.

Helps React optimize rendering by reordering elements instead of re-


rendering them entirely.

14. What is Relay in ReactJS?


JavaScript framework that handles data-fetching in web applications using
GraphQL, working with React components.

React JS Interview Qusestions 4


15. Difference between createElement and cloneElement :
createElement :

Creates a new React element.

Used to define UI components.

cloneElement :

Clones an existing element.

Allows modifying its props before rendering it again.

16. How to create components in React?


Functional Components:

JavaScript functions that take props as an argument.

Returns JSX.

Example:

js
Copy code
function Hello({ message }) {
return <h1>Hello, {message}</h1>;
}

Class Components:

Use ES6 classes to define components.

Can manage their own state.

Example:

js
Copy code
class App extends React.Component {
render() {

React JS Interview Qusestions 5


return <h2>Hello, {this.props.message}</h2>;
}
}

17. What is React State?


States are dynamic and mutable data structures that hold component-specific
data.

Accessible via this.state .

Used to trigger re-renders when the data changes.

18. What are React Props?


Props are read-only inputs passed from parent to child components.

Cannot be modified within the child component.

Allow for reusable components with dynamic data.

19. What are Default Props?


Default values provided for component props if none are supplied.

Example:

js
Copy code
MyApp.defaultProps = {
randomObject: {}
};

20. Difference between State and Props in React:


State:

Mutable.

React JS Interview Qusestions 6


Maintained internally within the component.

Affects how the component renders.

Props:

Immutable.

Passed from parent components.

Used to configure components and pass data.

21. What is setState() in ReactJS?


Used to update the component's state.

Triggers a re-render when called.

Performs a shallow merge of the new and previous state.

22. Parameters of setState() :


Updater:

Object or function used to merge into the existing state.

Callback (optional):

Function executed after the state has been updated.

23. What is the Arrow Function in React?


A concise syntax for writing functions.

Automatically binds this context.

Example:

js
Copy code
render() {
return (<MyInput onChange={(e) => this.handleOnChange
(e)} />);

React JS Interview Qusestions 7


}

24. What is the Context in ReactJS?


Mechanism to pass data through the component tree without manually
passing props.

Used for global data like user authentication or theme settings.

Example:

js
Copy code
const { Provider, Consumer } = React.createContext(default
Value);

25. What are React Mixins?


Mixins were used to share behaviors between components.

Deprecated in favor of higher-order components (HOCs) and hooks.

26. What is context.consumer in React?


A React element that subscribes to context changes.

Uses a function to render the current context value.

Example:

js
Copy code
<MyContext.Consumer>
{value => /* Render something based on context value */}
</MyContext.Consumer>

React JS Interview Qusestions 8


27. What is React Fiber?
React's new reconciliation engine introduced in React 16.

Improves rendering performance by allowing incremental rendering,


prioritization, and pausing of tasks.

28. What is React Reconciliation?


The process React uses to determine whether to update the DOM.

Compares the new virtual DOM to the previous one and updates only the
changed elements.

29. What are Pure Components?


Components that render the same output given the same props and state.

Optimized by skipping unnecessary re-renders.

Example:

js
Copy code
class MyComponent extends React.PureComponent {
render() {
return <div>{this.props.name}</div>;
}
}

30. Why use JSX in React?


Faster than regular JavaScript as it is optimized during compilation.

Encourages the separation of concerns within components.

Type-safe, which helps in catching errors during compile time.

Simplifies writing templates as it resembles HTML.

React JS Interview Qusestions 9

You might also like