โ† All React Flashcard Decks

Javascript Flashcards

7 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Javascript flashcards as text
  1. Which command should be used to start a new React project?

    Answer: npx create-react-app my-app

    The command `npx create-react-app my-app` is the standard and recommended way to initiate a new React project. `npx` is a package runner that executes `create-react-app` without requiring a global installation, ensuring you always use the latest version. This command sets up a complete React development environment with all necessary configurations and boilerplate code.

  2. What does the command's reference to "my-app" mean? npx create-react-app my-app

    Answer: The title that you want to give your new app

    In the command `npx create-react-app my-app`, 'my-app' is a placeholder for the desired name of your new React application. When executed, `create-react-app` will create a new directory with this specified name, containing all the initial files and configurations for your project. You should replace 'my-app' with a descriptive name for your application.

  3. Which command is used to launch the local development server for React?

    Answer: npm start

    After setting up a React project, the `npm start` command is used to launch the local development server. This command compiles your React application and opens it in your web browser, typically at `http://localhost:3000`. It also enables hot-reloading, which automatically updates the browser whenever you save changes to your code.

  4. What is the children prop?

    Answer: A property that lets you set an object as a property

    The `children` prop in React is a special property that allows components to receive and render content passed between their opening and closing tags. While its primary use is for component composition and nesting, the value of the `children` prop itself can be a JavaScript object, such as a React element object, an array of elements, or even a string. Therefore, it functions as a property that can hold an object representing the nested content.

  5. React components must start with a capital letter

    Answer: True

    In React, it is a strict convention and requirement for all custom component names to begin with a capital letter. This naming convention allows React to differentiate between user-defined components and standard HTML elements, which always start with a lowercase letter. Failing to capitalize a component name will cause React to misinterpret it as a regular HTML tag, leading to rendering errors.

  6. When rendering a list using the JavaScript map() method, what is required for each element rendered?

    Answer: Key

    When rendering a list of elements using the JavaScript `map()` method in React, each item must be assigned a unique `key` prop. The `key` prop helps React efficiently identify which items have been added, removed, or changed, which is crucial for optimizing performance and maintaining the correct state of list items during updates. Without unique keys, React's reconciliation algorithm can behave unpredictably.

  7. Which of the following is NOT a rule for React Hooks?

    Answer: Hooks can only be called at the top level of a component

    React Hooks are specifically designed to be used exclusively within React function components. They cannot be called inside class components, as class components manage state and side effects using `this.state` and lifecycle methods. This fundamental rule ensures that Hooks provide a consistent and predictable way to use React features without the complexities of classes.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy