ReactJS Interview Questions and Explanations for Freshers
Basic ReactJS Interview Questions with Explanations
1. What is ReactJS?
ReactJS is a JavaScript library developed by Facebook for building user interfaces, especially
single-page applications. It helps create fast and interactive UIs using reusable components.
2. What are the features of ReactJS?
- JSX - A syntax extension that lets you write HTML in JavaScript.
- Components - Reusable, independent pieces of UI.
- Virtual DOM - Improves performance by updating only changed elements.
- One-way data binding - Data flows from parent to child.
- Unidirectional flow - Ensures data is predictable and easier to debug.
3. Difference between Class and Functional Components?
- Class Component: Uses ES6 classes, can use lifecycle methods, and state is managed using
`this.state`.
- Functional Component: A simpler syntax using functions; can use Hooks for state and side effects.
4. What is JSX?
JSX (JavaScript XML) allows you to write HTML-like syntax in JavaScript files. It makes the code
easier to read and write.
Example: const element = <h1>Hello, world!</h1>;
5. What are props in React?
Props (short for "properties") are read-only inputs passed from a parent to a child component. They
help make components reusable.
6. What is state in React?
State is a built-in object used to contain data or information about the component. It can be changed
within the component and triggers a re-render.
7. Difference between props and state?
Props: Immutable, passed by parent, used for communication.
State: Mutable, managed inside component, used to control behavior.
8. How do you create a React app?
You can use the create-react-app CLI tool:
npx create-react-app my-app
cd my-app
npm start
9. What is the virtual DOM?
The Virtual DOM is a lightweight copy of the actual DOM. React updates the virtual DOM first,
compares it with the previous version (diffing), and then updates only the changed parts in the real
DOM.
10. What is the render() method?
In class components, render() returns the JSX that should be rendered on the screen.