0
0
Reactframework~5 mins

JSX syntax rules in React - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A<div>(5 + 5)</div>
B<div>{5 + 5}</div>
C<div>5 + 5</div>
D<div>${5 + 5}</div>
What attribute do you use to add CSS classes in JSX?
AstyleClass
Bclass
CcssClass
DclassName
Which JSX snippet is valid?
A<div><p>Hello</p><p>World</p></div>
B<p>Hello</p><p>World</p>
C<div><p>Hello</p><p>World</p>
D<div><p>Hello</p></div><p>World</p>
How should you write a self-closing tag for an image in JSX?
A<img>
B<img></img>
C<img />
D<img/>
Can you use statements like if or for directly inside JSX?
ANo, use JavaScript before JSX or use conditional expressions
BYes, directly inside JSX
CYes, but only if wrapped in curly braces
DNo, JSX does not support any JavaScript
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.