Pie Logo
Quiz: JSX and Components
by Tomas Trescak

QuizTest your understanding of the section content.

ContentDetailed description of the section content.

Full Stack Development
Introduction
Generative AI
🍰 Player
💼 Editor
Setup
React Fundamentals
JSX and Components
Quiz: JSX and Components
Props
Assignment 1.2: Front End
CSS Styles
useState and Hooks
Conditional Rendering
Lists
Forms and Events
Storybook
Assignment 1.3: Bonus - Backend
Leaderboards
Next.js
Advanced React
Databases
React Hooks
Authentication and Authorisation
APIs
CI/CD and DevOps
Testing React
Advanced Topics
    Pie Logo
    Quiz: JSX and Components
    by Tomas Trescak

    QuizTest your understanding of the section content.

    ContentDetailed description of the section content.

    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    JSX and Components
    Quiz: JSX and Components
    Props
    Assignment 1.2: Front End
    CSS Styles
    useState and Hooks
    Conditional Rendering
    Lists
    Forms and Events
    Storybook
    Assignment 1.3: Bonus - Backend
    Leaderboards
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics

    Quiz: JSX and Components
    by Tomas Trescak· JSX and Components

    QUESTION 1

    Imagine you’re building a simple React app for a blog website. You write the following JSX code inside a component:

    function BlogPost() {
      const title = "My First Post";
      return (
        <div>
          <h1>{title}</h1>
          <p>Welcome to my blog!</p>
        </div>
      );
    }
    

    What is true about this code?


    QUESTION 2

    You’re tasked with adding a button to a React component that logs "Clicked!" to the console when pressed. Here’s the code:

    function Button() {
      function handleClick() {
        console.log("Clicked!");
      }
      return <button onClick={handleClick}>Press Me</button>;
    }
    

    What can you say about the event handling in this code?


    QUESTION 3

    You’re refactoring a component that renders a list of items. The original code uses a <div> wrapper:

    function ItemList() {
      return (
        <div>
          <li>Item 1</li>
          <li>Item 2</li>
        </div>
      );
    }
    

    You decide to use a React fragment instead. Which of these options correctly replaces the <div> with a fragment?


    QUESTION 4

    You’re designing a greeting component for a website. Here’s the code:

    function Greeting(props) {
      const name = props.name;
      return <h1>Hello, {name}!</h1>;
    }
    

    A junior developer reviews it and suggests changes, such as adding interactivity when the user clicks the greeting or improving the component's memory footprint. Which of these suggestions would improve or maintain the component’s functionality?


    QUESTION 5

    Suppose you’re building a counter app with this code:

    function Counter() {
      let count = 0;
      function increment() {
        count += 1;
        console.log(count);
      }
      return (
        <>
          <p>Count: {count}</p>
          <button onClick={increment}>Add 1</button>
        </>
      );
    }
    

    You test it, click the button, and notice something odd. What’s happening, and why?

    This content is only available to registered users.
    Please register at the the home page.

    Quiz: JSX and Components
    by Tomas Trescak· JSX and Components

    QUESTION 1

    Imagine you’re building a simple React app for a blog website. You write the following JSX code inside a component:

    function BlogPost() {
      const title = "My First Post";
      return (
        <div>
          <h1>{title}</h1>
          <p>Welcome to my blog!</p>
        </div>
      );
    }
    

    What is true about this code?


    QUESTION 2

    You’re tasked with adding a button to a React component that logs "Clicked!" to the console when pressed. Here’s the code:

    function Button() {
      function handleClick() {
        console.log("Clicked!");
      }
      return <button onClick={handleClick}>Press Me</button>;
    }
    

    What can you say about the event handling in this code?


    QUESTION 3

    You’re refactoring a component that renders a list of items. The original code uses a <div> wrapper:

    function ItemList() {
      return (
        <div>
          <li>Item 1</li>
          <li>Item 2</li>
        </div>
      );
    }
    

    You decide to use a React fragment instead. Which of these options correctly replaces the <div> with a fragment?


    QUESTION 4

    You’re designing a greeting component for a website. Here’s the code:

    function Greeting(props) {
      const name = props.name;
      return <h1>Hello, {name}!</h1>;
    }
    

    A junior developer reviews it and suggests changes, such as adding interactivity when the user clicks the greeting or improving the component's memory footprint. Which of these suggestions would improve or maintain the component’s functionality?


    QUESTION 5

    Suppose you’re building a counter app with this code:

    function Counter() {
      let count = 0;
      function increment() {
        count += 1;
        console.log(count);
      }
      return (
        <>
          <p>Count: {count}</p>
          <button onClick={increment}>Add 1</button>
        </>
      );
    }
    

    You test it, click the button, and notice something odd. What’s happening, and why?

    This content is only available to registered users.
    Please register at the the home page.

    Pie Logo
    Quiz: JSX and Components
    by Tomas Trescak
    Pie Logo
    Quiz: JSX and Components
    by Tomas Trescak
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    JSX and Components
    Quiz: JSX and Components
    Props
    Assignment 1.2: Front End
    CSS Styles
    useState and Hooks
    Conditional Rendering
    Lists
    Forms and Events
    Storybook
    Assignment 1.3: Bonus - Backend
    Leaderboards
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    JSX and Components
    Quiz: JSX and Components
    Props
    Assignment 1.2: Front End
    CSS Styles
    useState and Hooks
    Conditional Rendering
    Lists
    Forms and Events
    Storybook
    Assignment 1.3: Bonus - Backend
    Leaderboards
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics