React JS Multiple-Choice Questions Answers (MCQs) — Codeymaze

CodeyMaze
2 min readJun 12, 2024

--

React JS, commonly referred to as React, is a popular JavaScript library for building user interfaces, particularly for single-page applications where the goal is to create a fast, interactive, and dynamic user experience.

Developed and maintained by Facebook, React allows developers to create reusable UI components, manage the state of applications efficiently, and build large-scale applications with ease.

In this article, we will share some React JS MCQ questions with answers that helps you to prepare for your next interview.

Multiple Choice Questions with Answers

Q1. Which method in React is used to update the state of a component?

  • updateState()
  • setState()
  • refreshState()
  • changeState()

=> setState()

Q2. Using which of the following command can prevent default behaviour at in react?

  • preventDefault()
  • prevent()
  • avoidDefault()
  • None of the above

=> preventDefault()

Q3. How do you pass data to a child component in React?

  • Using states
  • Using props
  • Using context
  • Using hooks

=> Using props

Q4. Which hook is used to handle side effects in a functional component?

  • useState
  • useEffect
  • useReducer
  • useContext

=> useEffect

Q5. What is used to handle code-splitting?

  • React.memo
  • React.lazy
  • React.fallback
  • React.context

=> React.lazy

Q6. What is the purpose of useCallback in React?

  • To manage component state
  • To prevent unnecessary re-renders of functions
  • To handle side effects
  • To create ref objects

=> To prevent unnecessary re-renders of functions

Q7. What will happen if you call setState() with the same state repeatedly?

  • It will re-render the component each time
  • It will cause an error
  • React will skip the re-render if the state is the same
  • It will log a warning to the console

=> React will skip the re-render if the state is the same

Q8. How can you prevent a function from being recreated on every render?

  • By using useMemo
  • By using useCallback
  • By using useRef
  • By using useEffect

=> By using useCallback

Q9. Which of the following is used to describe more about React application ?

  • Declarative
  • Integrated
  • Closed
  • Impressive

=> Declarative

Q10. Which hook would you use to persist a value across renders without causing re-renders?

  • useState
  • useMemo
  • useCallback
  • useRef

=> useRef

Q11. What is the return type of useState hook?

  • A single value
  • An array with two elements
  • An object with two properties
  • A function

=> An array with two elements

Q12. When does the function passed to useEffect run?

  • After every render
  • Before every render
  • Only on mount
  • Only on unmount

=> After every render

Originally published at https://codeymaze.com on June 12, 2024.

--

--

CodeyMaze
CodeyMaze

Written by CodeyMaze

Crafting Solutions Through Code & Words https://codeymaze.com Feel free to follow me :)

No responses yet