Create New Post

React MCQ

React Basics:

  1. What is React?

    • A. A programming language
    • B. A JavaScript library for building user interfaces
    • C. A CSS preprocessor
    • D. A server-side scripting language

    Answer: B. A JavaScript library for building user interfaces

  2. What does JSX stand for?

    • A. JavaScript XML
    • B. JavaScript Extension
    • C. JSX doesn't stand for anything
    • D. Java XML Syntax

    Answer: A. JavaScript XML

  3. Which method is used to render a React element into a DOM element?

    • A. renderDOM
    • B. mount
    • C. renderElement
    • D. ReactDOM.render

    Answer: D. ReactDOM.render

  4. In React, what is the purpose of setState?

    • A. To set the initial state of a component
    • B. To update the state of a component
    • C. To get the current state of a component
    • D. To remove a component from the state

    Answer: B. To update the state of a component

  5. What is the Virtual DOM used for in React?

    • A. To create a virtual representation of the browser
    • B. To store component styles
    • C. To improve performance by updating the actual DOM more efficiently
    • D. To handle asynchronous events

    Answer: C. To improve performance by updating the actual DOM more efficiently

Component Lifecycle:

  1. Which lifecycle method is called after a component renders for the first time?

    • A. componentWillMount
    • B. componentDidMount
    • C. componentWillUpdate
    • D. componentDidUpdate

    Answer: B. componentDidMount

  2. In class components, which method is used to update the state based on props changes?

    • A. componentDidMount
    • B. componentDidUpdate
    • C. componentWillReceiveProps
    • D. componentWillUpdate

    Answer: C. componentWillReceiveProps

Hooks:

  1. Which hook is used for side effects in functional components?

    • A. useEffect
    • B. useSideEffect
    • C. useAsyncEffect
    • D. useLifecycle

    Answer: A. useEffect

  2. What is the purpose of the useState hook?

    • A. To define state in class components
    • B. To fetch data from an API
    • C. To manage state in functional components
    • D. To create a global state

    Answer: C. To manage state in functional components

Props and State:

  1. What is the key difference between state and props in React?

    • A. State is used for internal component data, while props are used for communication between components.
    • B. State is immutable, while props are mutable.
    • C. State is passed down from parent components, while props are defined within a component.
    • D. State is used only in class components, while props are used in functional components.

    Answer: A. State is used for internal component data, while props are used for communication between components.

  2. In React, how can you pass data from a parent component to a child component?

    • A. Using the setState method
    • B. Using the props attribute
    • C. Using the state attribute
    • D. Using the render method

    Answer: B. Using the props attribute

React Router:

  1. What is React Router used for?

    • A. State management in React applications
    • B. Handling routing and navigation in React applications
    • C. Managing API requests
    • D. Styling React components

    Answer: B. Handling routing and navigation in React applications

  2. Which component is used to define a route in React Router?

    • A. Router
    • B. Switch
    • C. Route
    • D. Link

    Answer: C. Route

Redux:

  1. What is Redux used for in a React application?

    • A. Styling React components
    • B. Managing global state
    • C. Handling routing and navigation
    • D. Fetching data from an API

    Answer: B. Managing global state

  2. What is an action in Redux?

    • A. A plain JavaScript object describing a change in state
    • B. A function that calculates the next state
    • C. A middleware for handling side effects
    • D. A component in a Redux application

    Answer: A. A plain JavaScript object describing a change in state

Higher-Order Components (HOC):

  1. What is a Higher-Order Component (HOC) in React?

    • A. A component with a higher number of children
    • B. A function that takes a component and returns a new component with enhanced features
    • C. A component with a higher level of state
    • D. A component that renders other components

    Answer: B. A function that takes a component and returns a new component with enhanced features

React Context:

  1. What is React Context used for?

    • A. Managing global state
    • B. Styling React components
    • C. Handling routing and navigation
    • D. Creating higher-order components

    Answer: A. Managing global state

  2. How can you consume a React Context in a functional component?

    • A. Using the this.context property
    • B. Using the useContext hook
    • C. Using the Consumer component
    • D. Using the connect function

    Answer: B. Using the useContext hook

Portals:

  1. What is a React Portal used for?

    • A. Handling API requests
    • B. Rendering components outside the normal component hierarchy
    • C. Managing global state
    • D. Animating React components

    Answer: B. Rendering components outside the normal component hierarchy

Testing:

  1. Which testing library is commonly used for testing React components?

    • A. Jest
    • B. Mocha
    • C. Jasmine
    • D. Enzyme

    Answer: A. Jest

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

30726