React Basics Fundamentals Quiz
This quiz covers foundational topics in React, including:
- Basic Concepts: React structure, JSX, and component types.
- State and Props: Managing data within and across components.
- Hooks:
useState
and useEffect
. - Lifecycle Methods: Managing React component lifecycles.
- Advanced Topics: Context API, keys, and fragments.
This will help you evaluate your understanding of React fundamentals!
Question 1. What is React?
Explanation: React is a JavaScript library for building user interfaces, maintained by Facebook and a community of developers.
Question 2. What is JSX?
-
A.
A template engine
-
B.
A new programming language
-
C.
JavaScript XML, a syntax extension for JavaScript
-
D.
A type of JavaScript library
Explanation: JSX allows us to write HTML in React. It makes the code more readable and easier to write.
Question 3. Which method is used to update the state in a React component?
-
A.
updateState()
-
B.
setState()
-
C.
stateChange()
-
D.
changeState()
Explanation: setState() is the only way to update the state of a React component.
Question 4. What are props in React?
Explanation: Props are short for "properties" and allow passing data from a parent to a child component.
Question 5. Which of the following is used to create a functional component in React?
Explanation: Functional components in React are JavaScript functions that return JSX.
Question 6. What is the default port for a React application?
-
A.
3000
-
B.
8080
-
C.
5000
-
D.
8000
Explanation: React applications run on port 3000 by default.
Question 7. Which of the following lifecycle methods is called when a component is first added to the DOM?
-
A.
componentDidMount
-
B.
componentWillUpdate
-
C.
shouldComponentUpdate
-
D.
componentDidUpdate
Explanation: componentDidMount() is invoked after a component is mounted to the DOM.
Question 8. What does the useState hook do in React?
Explanation: useState is a hook that lets you add React state to functional components.
Question 9. How do you pass data from a parent to a child component in React?
-
A.
Through state
-
B.
Using props
-
C.
With hooks
-
D.
Using context
Explanation: Props are used to pass data from parent to child components.
Question 10. What does the key prop do in React?
-
A.
Creates a unique identifier for each component
-
B.
Adds styles
-
C.
Attaches an event listener
-
D.
Optimizes component rendering
Explanation: The key prop helps React identify which items have changed, added, or removed in a list, optimizing rendering.
Question 11. Which statement is true about React fragments?
-
A.
They modify DOM structure.
-
B.
They are used to group multiple elements without adding extra nodes to the DOM.
-
C.
They are stateful components.
-
D.
They only work with class components.
Explanation: React fragments allow you to group a list of children without adding extra nodes to the DOM.
Question 12. What does useEffect do?
Explanation: useEffect is a hook for performing side effects like fetching data or updating the DOM.
Question 13. Which React function creates a virtual DOM element?
-
A.
React.createElement()
-
B.
React.createComponent()
-
C.
React.render()
-
D.
React.init()
Explanation: React.createElement() creates virtual DOM elements.
Question 14. What is the purpose of React's Context API?
Explanation: Context API provides a way to share values between components without explicitly passing props.
Question 15. What is the React Developer Tools browser extension used for?
Explanation: React Developer Tools is a browser extension for inspecting the structure and behavior of React components.
Share Quiz Result