JSX — Markup That Is Really JavaScript — Concept Check
Questions on JSX — Markup That Is Really JavaScript. JSX compiles to function calls. Knowing that explains every rule it has, including the ones that look arbitrary.
Questions in this quiz
8 questions on JSX — Markup That Is Really JavaScript — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have a JSX snippet: `<button class='primary'>Click</button>`. Why does this cause an error?
- A'class' is a reserved word in JavaScript, use 'className' instead
- BJSX requires all attributes to be camelCase
- CJSX does not support button elements
- DAttributes must be wrapped in curly braces
2.A component returns multiple root elements without using a Fragment. What happens?
- AThe component will render all elements correctly
- BThe component will throw an error during compilation
- CThe component will render only the first root element
- DThe component will render a blank screen
3.Why does `{count && <Badge count={count} />}` sometimes render '0'?
- A'0' is coerced to a boolean, causing it to render
- BJSX treats '0' as a falsy value and skips rendering
- CJSX automatically converts numbers to strings
- D'0' is a number, which does render, unlike null or false
4.Given the JSX: `<img src={imageSrc} alt='Image' />`, what is required for 'src'?
- A'src' must be a JavaScript expression
- B'src' must be a valid URL string
- C'src' must be a static string
- D'src' must be wrapped in curly braces
5.What is the purpose of `dangerouslySetInnerHTML` in JSX?
- ATo prevent XSS attacks
- BTo automatically sanitize user input
- CTo safely escape HTML content
- DTo render raw HTML content inside an element
6.Why can't you use `if` statements directly inside JSX expressions?
- AJSX automatically converts 'if' to ternary operators
- BJSX expressions can only contain JavaScript expressions, not statements
- C'if' statements require a return value
- DJSX does not support conditional rendering
7.In JSX, why is it recommended to use camelCase for inline styles?
- AHTML attributes are always camelCase
- BJSX converts camelCase to kebab-case automatically
- CCamelCase is required for all JSX attributes
- DJSX inline styles are JavaScript objects, which use camelCase
8.What happens if you try to use `for` as an attribute in JSX?
- AIt causes a syntax error because 'for' is a reserved word
- BIt works without any issues
- CIt renders as a plain text attribute
- DIt gets automatically converted to 'htmlFor'