React Interview Questions

1. What is the correct command to create a new React project?

Ans- Select one

  • npx create-react-app myReactApp
  • npx create-react-app
  • npm create-react-app myReactApp
  • npm create-react-app

2. What does myReactApp refer to in the following command?

npx create-react-app myReactApp

    Ans- Select one

    • A reference to an existing app
    • The type of app to create
    • The directory to create the new app in
    • The name you want to use for the new app
    3. What command is used to start the React local development server?

    4. What is the default local host port that a React development server uses?

    5. To develop and run React code, Node.js is required.

    6. What type of element will be rendered from the following code?

    function Car() {
      return <h1>Ford Mustang</h1>;
    }

    const root = createRoot(document.getElementById('root'));
    root.render(<Car />);

    7. What is the children prop?

    8. Which keyword creates a constant in JavaScript?

    9.  A copy of the 'real' DOM that is kept in memory is called what?

    10. React component names must begin with an uppercase letter.

    11. Which operator can be used to conditionally render a React component?

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

    13. What tool does React use to compile JSX?

    14. How can you optimize performance for a function component that always renders the same way?

    15. What props will be available to the following component?

    <Car {...props} />

    16. What is a common use case for ref?

    17. How can you combine the following arrays using the spread operator?

    const array1 = [1, 2, 3];
    const array2 = [4, 5, 6];

    18. React can only render elements in the root document element.

    19. What is the correct syntax to import a Component from React?

    20. Find the bug in this code:

    function car({make, model}) {
      return <h1>{make} {model}</h1>;
    };

    21. React separates the user interface into components. How are components combinded to create a user interface?

    22. Although React Hooks generally replace class components, there are no plans to remove classes from React.

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

    24. What is the output of the following code?

    const make = 'Ford';
    const model = 'Mustang';
    const car = { make, model };
    console.log(car);

    25. Why should you avoid copying the values of props into a component's state?