Recall & Review
beginner
What is JSX in React?
JSX is a syntax that looks like HTML but is used in React to describe what the UI should look like. It lets you write HTML-like code inside JavaScript.
Click to reveal answer
beginner
How do you embed JavaScript expressions inside JSX?
You put JavaScript expressions inside curly braces {} within JSX. For example:
{2 + 2} will show 4.Click to reveal answer
beginner
Why must JSX elements have one parent element?
JSX must return a single root element because React needs one element to represent the component. You can wrap multiple elements in a
<div> or <React.Fragment>.Click to reveal answer
beginner
How do you add CSS classes in JSX?
Use
className instead of class because class is a reserved word in JavaScript. For example: <div className="box"></div>.Click to reveal answer
beginner
What is the rule for self-closing tags in JSX?
All tags without children must be self-closed with a slash. For example,
<img src="image.png" /> or <br />.Click to reveal answer
Which of these is the correct way to write a JSX element with a JavaScript expression?
✗ Incorrect
JavaScript expressions must be inside curly braces {} in JSX.
What attribute do you use to add CSS classes in JSX?
✗ Incorrect
JSX uses 'className' instead of 'class' because 'class' is a reserved word in JavaScript.
Which JSX snippet is valid?
✗ Incorrect
JSX must have one parent element wrapping all children.
How should you write a self-closing tag for an image in JSX?
✗ Incorrect
Self-closing tags must include a slash before the closing angle bracket in JSX. Both
and
are valid.
Can you use statements like if or for directly inside JSX?
✗ Incorrect
JSX supports expressions inside curly braces, but statements like if or for must be handled outside or with conditional expressions.
Explain the main rules you must follow when writing JSX syntax.
Think about how JSX mixes HTML and JavaScript and what special syntax it requires.
You got /5 concepts.
Describe how to include JavaScript logic like conditions or loops when using JSX.
Remember JSX allows expressions but not statements inside its syntax.
You got /4 concepts.