React Quiz

React is a JavaScript library for building user interfaces from reusable components. The questions here cover JSX, components, props, state, hooks and the rendering model, which are the ideas every React job interview starts with.

What this quiz covers

Study tip: Build a small to-do app while you study; most beginner React questions map directly to something you will use in it.

Questions, answers and explanations

1. What is React.js?

  1. Open-source JavaScript back-end library
  2. JavaScript front-end library to create a database
  3. Free and open-source JavaScript front-end library
  4. None of the mentioned

Answer: Free and open-source JavaScript front-end library

React is a free and open-source JavaScript library for building user interfaces.

2. What is JSX in React?

  1. JavaScript Execution
  2. JavaScript XML
  3. JavaScript Extra
  4. None of the mentioned

Answer: JavaScript XML

JSX stands for JavaScript XML and lets you write HTML-like syntax inside JavaScript.

3. React.js is primarily used for which of the following?

  1. Backend Development
  2. Database Management
  3. Frontend Development
  4. Mobile App Development

Answer: Frontend Development

React is mainly used for building interactive user interfaces.

4. Which of the following acts as the input of a class-based component?

  1. Class
  2. Props
  3. Factory
  4. None of the mentioned

Answer: Props

Props are used to pass data into React components.

5. What is the main purpose of JSX in React?

  1. Database Query Language
  2. JavaScript Function
  3. CSS Styling
  4. HTML-like syntax

Answer: HTML-like syntax

JSX allows developers to write HTML-like code inside JavaScript.

6. React.js is written in which language?

  1. C
  2. C++
  3. JavaScript
  4. Java

Answer: JavaScript

React is built using JavaScript.

7. How many elements can a valid React component return?

  1. React doesn't return elements
  2. 1 Element
  3. More than 1 element
  4. None of the mentioned

Answer: 1 Element

A component must return one parent element. Multiple elements can be wrapped in a Fragment.

8. In which directory are React components commonly stored?

  1. js/components/
  2. components/js/
  3. vendor/js/components/
  4. vendor/components/

Answer: js/components/

Many React projects store components inside a components folder.

9. Which command installs Create React App globally?

  1. npm install create-react-app
  2. npm install -f create-react-app
  3. npm install -g create-react-app
  4. install -g create-react-app

Answer: npm install -g create-react-app

Historically, Create React App could be installed globally. Today, using 'npx create-react-app' is recommended.

10. Which hook is used to manage state in functional components?

  1. useState
  2. useReducer
  3. useEffect
  4. useRef

Answer: useState

useState is the basic React Hook for managing state.

11. Which of the following is NOT part of ReactDOM?

  1. ReactDOM.hydrate()
  2. ReactDOM.destroy()
  3. ReactDOM.createPortal()
  4. All of the mentioned

Answer: ReactDOM.destroy()

ReactDOM has methods like render, hydrate, and createPortal, but not destroy().

12. Which statement is correct about props in React?

  1. Can be changed inside another component
  2. Can be changed inside the component
  3. Cannot be changed in the component
  4. All of the mentioned

Answer: Cannot be changed in the component

Props are read-only (immutable) inside the receiving component.

13. What is the Virtual DOM in React?

  1. A DOM management system
  2. A method to update the real DOM directly
  3. A server-side DOM
  4. A virtual version of the actual DOM

Answer: A virtual version of the actual DOM

React compares the Virtual DOM with the real DOM to update only the necessary parts.

14. How do you pass data to a React component?

  1. props
  2. render with arguments
  3. setState
  4. PropTypes

Answer: props

Props are used to pass data from a parent component to a child component.

15. What is the purpose of React.StrictMode?

  1. To add animations
  2. To improve performance
  3. To enhance UI
  4. To add additional validation checks

Answer: To add additional validation checks

StrictMode helps identify potential problems during development.

16. Which of the following is NOT a valid React Hook?

  1. useContext
  2. useState
  3. useReturn
  4. useEffect

Answer: useReturn

There is no Hook named useReturn.

17. How do you create a React application?

  1. Using Node.js
  2. Writing plain JavaScript
  3. Using the 'npx create-react-app' command
  4. Using HTML

Answer: Using the 'npx create-react-app' command

Traditionally, React apps are created with Create React App. Modern projects often use Vite.

18. Which statement about React components is true?

  1. A component must return only a single parent element
  2. A component cannot accept props
  3. A component must be a function
  4. A component cannot have state

Answer: A component must return only a single parent element

Components return one parent element, or a React Fragment.

19. In React, what is a component?

  1. A method used for side effects
  2. A function that takes props and returns UI
  3. A class used to manage state
  4. A system for routing

Answer: A function that takes props and returns UI

Components are reusable building blocks that return UI.

20. Which statement about React Hooks is true?

  1. Hooks can be used in class components
  2. Hooks can only be used in functional components
  3. Hooks are used to manage props
  4. Hooks are not supported in React

Answer: Hooks can only be used in functional components

Hooks are designed for functional components.

Take the timed quiz