Bird
Raised Fist0
Reactframework~10 mins

What is JSX in React - Interactive Quiz & Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a React component that returns a heading using JSX.

React
function Hello() {
  return ([1]);
}
Drag options to blanks, or click blank then click option'
Aconsole.log('Hello, world!')
B"Hello, world!"
C<h1>Hello, world!</h1>
DReact.createElement('h1', null, 'Hello, world!')
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a string instead of JSX
Using console.log inside return
Using React.createElement instead of JSX here
2fill in blank
medium

Complete the JSX code to display a paragraph with the text 'Welcome to React!'.

React
const element = [1];
Drag options to blanks, or click blank then click option'
A{Welcome to React!}
B"Welcome to React!"
CReact.createElement('p', null, 'Welcome to React!')
D<p>Welcome to React!</p>
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes without tags
Using curly braces without tags
Using React.createElement instead of JSX here
3fill in blank
hard

Fix the error in this JSX code by completing the blank.

React
const element = <div>[1]Hello</div>;
Drag options to blanks, or click blank then click option'
A{' '}
B' '
C" "
D<br/>
Attempts:
3 left
💡 Hint
Common Mistakes
Using plain quotes inside JSX tags
Using HTML tags like
incorrectly
Leaving no space causing words to stick together
4fill in blank
hard

Fill both blanks to create a JSX expression that shows a list of items from an array.

React
const items = ['Apple', 'Banana', 'Cherry'];
const list = <ul>[1].map((item) => <li key={item}>[2]</li>)</ul>;
Drag options to blanks, or click blank then click option'
Aitems
Bitem
Cfruits
Dfruit
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names like 'fruits' or 'fruit'
Not using map to loop over the array
Forgetting to use key attribute in list items
5fill in blank
hard

Fill all three blanks to create a React component that uses JSX to display a greeting with a name prop.

React
function Greeting([1]) {
  return <h1>Hello, [2]!</h1>;
}

const element = <Greeting [3]="Alice" />;
Drag options to blanks, or click blank then click option'
Aname
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the prop in different places
Forgetting to destructure props in the function parameter
Passing props with wrong attribute names

Practice

(1/5)
1. What is JSX in React?
easy
A. A syntax that lets you write HTML-like code inside JavaScript
B. A CSS framework for styling React components
C. A database query language used with React
D. A tool to compile JavaScript into machine code

Solution

  1. Step 1: Understand JSX purpose

    JSX allows writing HTML-like tags directly in JavaScript code, making UI code easier to write and read.
  2. Step 2: Identify incorrect options

    Options B, C, and D describe unrelated tools or concepts not connected to JSX.
  3. Final Answer:

    A syntax that lets you write HTML-like code inside JavaScript -> Option A
  4. Quick Check:

    JSX = HTML-like code in JavaScript [OK]
Hint: JSX looks like HTML but is inside JavaScript code [OK]
Common Mistakes:
  • Confusing JSX with CSS or styling tools
  • Thinking JSX is a separate language
  • Believing JSX is a database query language
2. Which of the following is the correct way to write a JSX element?
easy
A. <div>Hello World
B. div>Hello World
C.
Hello World
D. {div}Hello World{/div}

Solution

  1. Step 1: Check JSX tag syntax

    JSX elements must have opening and closing tags properly enclosed in angle brackets, like <div>Hello World</div>.
  2. Step 2: Identify syntax errors in other options

    div>Hello World</div> misses the opening angle bracket, C misses the closing tag, and D uses curly braces incorrectly.
  3. Final Answer:

    <div>Hello World</div> -> Option C
  4. Quick Check:

    Proper JSX tags use <tag>content</tag> [OK]
Hint: JSX tags look like HTML tags with < and > [OK]
Common Mistakes:
  • Omitting angle brackets around tags
  • Forgetting closing tags
  • Using curly braces instead of angle brackets for tags
3. What will this JSX code render?
const element = <h1>Hello, {"React"} & JSX!</h1>;
ReactDOM.render(element, document.getElementById('root'));
medium
A. Hello, {"React"} & JSX!
B. SyntaxError due to curly braces
C.

Hello, React & JSX!

D.

Hello, React & JSX!

Solution

  1. Step 1: Understand JSX expression inside curly braces

    The string "React" inside curly braces is evaluated and inserted as text inside the h1 element.
  2. Step 2: Recognize HTML entities and output

    The & symbol renders as & in the browser, so the final rendered text is Hello, React & JSX! inside an h1 tag.
  3. Final Answer:

    <h1>Hello, React & JSX!</h1> -> Option D
  4. Quick Check:

    JSX expressions render evaluated content [OK]
Hint: Curly braces insert JavaScript values inside JSX [OK]
Common Mistakes:
  • Thinking curly braces print raw code
  • Confusing HTML entities with literal text
  • Expecting syntax error from curly braces
4. Identify the error in this JSX code:
const element = <div>Hello {name}</div>
ReactDOM.render(element, document.getElementById('root'));
Assuming name is not defined anywhere.
medium
A. ReferenceError because 'name' is not defined
B. SyntaxError due to missing quotes around name
C. Renders 'Hello name' as plain text
D. No error, renders empty space after Hello

Solution

  1. Step 1: Check variable usage inside JSX

    JSX expressions inside curly braces expect valid JavaScript variables or expressions. Here, 'name' is not defined.
  2. Step 2: Understand runtime behavior

    Using an undefined variable causes a ReferenceError at runtime, stopping rendering.
  3. Final Answer:

    ReferenceError because 'name' is not defined -> Option A
  4. Quick Check:

    Undefined variables in JSX cause ReferenceError [OK]
Hint: Variables in JSX must be defined before use [OK]
Common Mistakes:
  • Assuming missing quotes cause syntax error
  • Thinking JSX prints variable names as text
  • Believing undefined variables render empty strings
5. How can you include a JavaScript expression inside JSX to display the sum of 2 + 3?
hard
A.

The sum is {"2 + 3"}

B.

The sum is {2 + 3}

C.

The sum is (2 + 3)

D.

The sum is "2 + 3"

Solution

  1. Step 1: Use curly braces for JavaScript expressions in JSX

    JSX lets you insert JavaScript expressions inside curly braces to evaluate and display their result.
  2. Step 2: Evaluate each option's expression

    The sum is {2 + 3}

    correctly uses curly braces with 2 + 3, which evaluates to 5. Options A and B treat it as a string, and C uses parentheses without curly braces, so it won't evaluate.
  3. Final Answer:

    <p>The sum is {2 + 3}</p> -> Option B
  4. Quick Check:

    Curly braces evaluate JS expressions inside JSX [OK]
Hint: Use curly braces to evaluate expressions inside JSX [OK]
Common Mistakes:
  • Putting expressions inside quotes disables evaluation
  • Using parentheses without curly braces
  • Confusing strings with expressions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard