0
0
Reactframework~20 mins

JSX vs HTML differences in React - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSX Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
JSX attribute naming difference
What will be the rendered output of this React component regarding the attribute on the <input> element?
React
function MyInput() {
  return <input className="my-class" />;
}
AThe input will have no class because 'class' is invalid in JSX.
BThe input will have an attribute 'class' but React will warn about it.
CThe input will have a CSS class named 'my-class'.
DThe input will throw a syntax error because 'class' is not allowed.
Attempts:
2 left
💡 Hint
Remember that 'class' is a reserved keyword in JavaScript.
📝 Syntax
intermediate
2:00remaining
JSX self-closing tags requirement
Which option correctly writes the <img> element in JSX?
React
function Image() {
  return <img src="logo.png" />;
}
AChange to <img src="logo.png" />
BChange to <img src="logo.png"></img> (no change needed)
CChange to <img src="logo.png">
DChange to <img src="logo.png" />;</img>
Attempts:
2 left
💡 Hint
Think about how void elements like <img> should be handled in JSX.
🔧 Debug
advanced
2:00remaining
Why does this JSX code cause an error?
Consider this React component code. Why does the event handler not work?
React
function Button() {
  return <button onClick={() => alert('Clicked!')}>Click me</button>;
}
ABecause the button element must be self-closing in JSX.
BBecause alert is not allowed inside JSX event handlers.
CBecause arrow functions cannot be used inside JSX attributes.
DBecause JSX uses camelCase for event handlers, it should be onClick, not onclick.
Attempts:
2 left
💡 Hint
Check the casing of event handler attributes in JSX.
state_output
advanced
2:00remaining
JSX expression evaluation inside attributes
What will be the value of the alt attribute in the rendered <img> element?
React
function Logo() {
  const name = 'React';
  return <img src="logo.png" alt={name + ' Logo'} />;
}
AThe alt attribute will be 'React Logo'.
BThe alt attribute will be '{name + ' Logo'}' as a string literal.
CThe alt attribute will be empty because expressions are not allowed.
DThe code will cause a syntax error due to string concatenation.
Attempts:
2 left
💡 Hint
Remember how JSX handles JavaScript expressions inside curly braces.
🧠 Conceptual
expert
3:00remaining
Why does JSX use 'htmlFor' instead of 'for' in labels?
In JSX, the <label> element uses htmlFor instead of the HTML attribute for. Why is this change necessary?
ABecause 'for' is deprecated in HTML5 and replaced by 'htmlFor'.
BBecause 'for' is a reserved keyword in JavaScript, so JSX uses 'htmlFor' to avoid conflicts.
CBecause React automatically converts 'for' to 'htmlFor' internally.
DBecause 'htmlFor' is the standard attribute in HTML, not 'for'.
Attempts:
2 left
💡 Hint
Think about JavaScript language rules and how JSX is JavaScript syntax.