ReactJS Interview Questions and Answer
Q: What is React?
React is a front-end JavaScript library developed by Facebook in 2011. It follows the component based approach which helps in building reusable UI components. It is used for developing complex and interactive web and mobile UI. Even though it was open-sourced only in 2015, it has one of the largest communities supporting it.
Q: What are the features of React?
JSX: JSX is JavaScript syntax extension.
Components: React is all about components.
One direction flow: React implements one-way data flow which makes it easy to reason about your app
Components: React is all about components.
One direction flow: React implements one-way data flow which makes it easy to reason about your app
Q: List some of the major advantages of React.
Some of the major advantages of React are:
- It increases the application’s performance
- It can be used on client and server side
- Code’s readability increases, because of JSX.
- It is easy to integrate with other frameworks such as Angular, Meteor etc
- Using React, writing UI test cases become extremely easy
- React uses virtual DOM which is a JavaScript object.
- This will improve apps performance
- Component and Data patterns improve readability.
Q: What are the limitations of React?
Limitations of React are listed below:
- React is just a library, not a full-blown framework
- Its library is very large and takes time to understand
- It can be little difficult for the novice programmers to understand
- Coding gets complex as it uses inline templating and JSX
Q: What is JSX?
JSX is a shorthand for JavaScript XML. This is a type of file used by React which utilizes the expressiveness of JavaScript along with HTML like template syntax. This makes the HTML file really easy to understand. This file makes applications robust and boosts its performance. Below is an example of JSX:
render(){
return(
<div>
<h1> Welcome To Tekslate!!</h1>
</div>
);
}
Q: Differentiate between Real DOM and Virtual DOM.
Real DOM | Virtual DOM |
It updates slowly. | It updates faster. |
Can directly update HTML. | Can’t directly update HTML. |
Creates a new DOM if element updates. | Updates the JSX if element updates. |
DOM manipulation is very expensive. | DOM manipulation is very easy. |
Too much of memory wastage. | No memory wastage. |
Q. Real DOM vs Virtual DOM
Browsers can only read JavaScript objects but JSX in not a regular JavaScript object. Thus to enable a browser to read JSX, first, we need to transform JSX file into a JavaScript object using JSX transformers like Babel and then pass it to the browser.
Q: How is React different from Angular?
React vs Angular
TOPIC | REACT | ANGULAR |
ARCHITECTURE | Only the View of MVC | Complete MVC |
RENDERING | Server side rendering | Client side rendering |
DOM | Uses virtual DOM | Uses real DOM |
DATA BINDING | One-way data binding | Two-way data binding |
DEBUGGING | Compile time debugging | Run time debugging |
AUTHOR |
Q: Why can’t browsers read JSX?
Components are the building blocks of a React application’s UI. These components split up the entire UI into small independent and reusable pieces. Then it renders each of these components independent of each other without affecting the rest of the UI.
Q: Explain the purpose of render() in React.
Each React component must have a render() compulsory. If more than one HTML elements need to be rendered, then they must be grouped together inside one enclosing tag such as <form>, <group>,<div> etc. It returns to the single react element which is the presentation of native DOM Component. This function must be kept pure i.e., it must return the same result each time it is invoked.
Q: What is Props?
Props are shorthand for Properties in React. They are read-only components which must be kept pure i.e. immutable. They are always passed down from the parent to the child components throughout the application. A child component can never send a prop back to the parent component. This help in maintaining the unidirectional data flow and are generally used to render the dynamically generated data.
Q: What is a state in React and how is it used?
States are the heart of React components. States are the source of data and must be kept as simple as possible. Basically, states are the objects which determine components rendering and behavior. They are mutable unlike the props and create dynamic and interactive components. They are accessed via this.state().
0 comments:
Post a Comment