Wednesday 25 April 2018

Reactjs Interview Question

1. 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.

2. What are the features of React?

Major features of React are listed below:
  1. It uses the virtual DOM instead of the real DOM.
  2. It uses server-side rendering.
  3. It follows uni-directional data flow or data binding.

3. List some of the major advantages of React.

Some of the major advantages of React are:
  1. It increases the application’s performance
  2. It can be conveniently used on the client as well as server side
  3. Because of JSX, code’s readability increases
  4. React is easy to integrate with other frameworks like Meteor, Angular, etc
  5. Using React, writing UI test cases become extremely easy

4. What are the limitations of React?

Limitations of React are listed below:
  1. React is just a library, not a full-blown framework
  2. Its library is very large and takes time to understand
  3. It can be little difficult for the novice programmers to understand
  4. Coding gets complex as it uses inline templating and JSX

5. 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:
1
2
3
4
5
6
7
render(){
   return(       
        <div>
           <h1> Hello World from Edureka!!</h1>
        </div>
   );
}

6.  Differentiate between Real DOM and Virtual DOM.

Real DOM vs Virtual DOM

Real DOM
Virtual  DOM
1. It updates slow.
1. It updates faster.
2. Can directly update HTML.
2. Can’t directly update HTML.
3. Creates a new DOM if element updates.
3. Updates the JSX if element updates.
4. DOM manipulation is very expensive.
4. DOM manipulation is very easy.
5. Too much of memory wastage.
5. No memory wastage.

7. Why can’t browsers read JSX?

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.

8. How is React different from Angular?

React vs Angular

TOPIC
REACT
ANGULAR
1. ARCHITECHTURE
Only the View of MVC
Complete MVC
2. RENDERING
Server side rendering
Client side rendering
3. DOM
Uses virtual DOM
Uses real DOM
4. DATA BINDING
One-way data binding
Two-way data binding
5. DEBUGGING
Compile time debugging
Run time debugging
6. AUTHOR
Facebook
Google

9. What do you understand from “In React, everything is a component.”

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.

10. Explain the purpose of render() in React.

Each React component must have a render() mandatorily. It returns a single React element which is the representation of the native DOM component. If more than one HTML element needs to be rendered, then they must be grouped together inside one enclosing tag such as <form>, <group>,<div> etc. This function must be kept pure i.e., it must return the same result each time it is invoked.

11. What is Props?

Props are short hand 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 through out 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.

12. 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().


13. Differentiate between states and props.


States vs Props

Conditions
State
Props
1. Receive initial value from parent component
Yes
Yes
2. Parent component can change value
No
Yes
3. Set default values inside component
Yes
Yes
4. Changes inside component
Yes
No
5. Set initial value for child components
Yes
Yes
6. Changes inside child components
No
Yes

14. Differentiate between stateful and stateless components.

Stateful vs Stateless Components React

Stateful Component
Stateless Component
1. Stores info about component’s state change in memory
1. Calculates the internal state of the components
2. Have authority to change state
2. Do not have the authority to change state
3. Contains the knowledge of past, current and possible future changes in state
3. Contains no knowledge of past, current and possible future state changes
4. Stateless components notify them about the requirement of the state change, then they send down the props to them.
4. They receive the props from the Stateful components and treat them as callback functions.

15. What are the different phases of React component’s lifecycle?

There are three different phases of React component’s lifecycle:
  1. Initial Rendering Phase: This is the phase when the component is about to start its life journey and make its way to the DOM.
  2. Updating Phase: Once the component gets added to the DOM, it can potentially update and re-render only when a prop or state change occurs. That happens only in this phase.
  3. Unmounting Phase: This is the final phase of a component’s life cycle in which the component is destroyed and removed from the DOM.

No comments:

Post a Comment