4. Identify the error in this Svelte component usage:
<script>
let props = {title: 'Hello'};
</script>
<Card {...props} title />
medium
A. Spread props cannot be used with explicit props.
B. The component tag must not be self-closing.
C. The object props must be declared inside the component.
D. Explicit prop title without a value sets it to true.
Solution
Step 1: Check explicit prop syntax
The explicit prop title without a value is treated as title={true} in Svelte.
Step 2: Understand Svelte prop override
This overrides the spread title='Hello' to true.
Final Answer:
Explicit prop title without value sets it to true. -> Option D
Quick Check:
Explicit props need values unless boolean [OK]
Hint: Explicit props must have values unless boolean attributes [OK]
Common Mistakes:
Thinking spread and explicit props can't be combined
Assuming missing value is allowed for any prop
Believing self-closing tags are invalid here
5. You have a Svelte component <Button /> that accepts props type, disabled, and label. You want to pass an object btnProps with {type: 'submit', disabled: false} but override disabled to true and add label as 'Send'. Which is the correct usage?
hard
A. <Button {...btnProps} disabled={true} label='Send' />
B. <Button disabled={true} label='Send' {...btnProps} />
C. <Button label='Send' disabled={true} {...btnProps} />
D. <Button {...btnProps} label='Send'; disabled={true} />
Solution
Step 1: Pass base props with spread first
Use {...btnProps} to pass type and disabled: false.
Step 2: Override disabled and add label explicitly
Explicit props after spread override previous values, so disabled={true} and label='Send' must come after.
Step 3: Check order of props
Only <Button {...btnProps} disabled={true} label='Send' /> places spread first, then explicit props, ensuring correct override.
Final Answer:
<Button {...btnProps} disabled={true} label='Send' /> -> Option A
Quick Check:
Spread first, explicit override after [OK]
Hint: Put spread props first, explicit props after to override [OK]
Common Mistakes:
Placing explicit props before spread, losing override effect
Duplicating props in wrong order
Forgetting to add new props explicitly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.