Thursday, November 23, 2023

ReactJS

 Here are some common ReactJS interview questions and answers:

Q1. What is ReactJS?

A1. ReactJS is an open-source, front-end JavaScript library developed by Facebook for building user interfaces or UI components. It follows the component based approach which helps in building reusable UI components.

Q2. What are the major features of ReactJS?

A2. Major features include:

- It uses VirtualDOM instead of RealDOM which is faster.

- It follows uni-directional data flow or one-way data binding.

- It uses reusable/composable UI components to develop the view.

- It is used for handling view layer only while Redux is used for state management.

- It uses server-side rendering for faster page load and better SEO.

Q3. What is JSX? 

A3. JSX is a HTML/XML-like syntax extension to JavaScript which is used in React for easily describing UI components. It is not valid JavaScript but gets transformed to JavaScript with transpilers like Babel. It makes code easy to read and write.

Q4. Difference between class and functional components

A4. Class components use ES6 class and render() method to return elements. Functional components use normal JavaScript functions to return elements. With hooks, functional components can now also use state and other features which were only for class components earlier.

Q5. What are state and props in React?

A5. State represents data maintained inside a component while props represent data passed from a parent component to a child component which is read-only for the receiving component. State data can be changed but triggers render while props are immutable.