This example shows a Card component with named slots for header and footer, plus a default slot for the body. The App component fills each slot with custom content.
Assuming MyComponent defines named slots header and footer.
medium
A. Slots must be direct children of the component, so this is invalid
B. Multiple elements use the same slot name 'header', causing only the last to render
C. Slot names must be unique and cannot be reused in the same component usage
D. There is no error; all content will render in the header slot
Solution
Step 1: Check multiple slot usage
When multiple elements use the same slot name, only the last one is rendered in that slot.
Step 2: Understand slot content replacement
The first header content is replaced by the second because slots accept one content block per name.
Final Answer:
Multiple elements use the same slot name 'header', causing only the last to render -> Option B
Quick Check:
Duplicate slot names = last content wins [OK]
Hint: Only one content block per named slot is rendered [OK]
Common Mistakes:
Thinking all duplicates render together
Believing slot names must be unique globally
Assuming nested slots behave differently
5. You want to create a Svelte component Card with named slots for header, content, and footer. You also want to provide default content for each slot if none is passed. Which code snippet correctly implements this?
hard
A. Default Header
Default Content
Default Footer
B. Default Header
Default Content
Default Footer
C.
D. Default Header
Default Content
Default Footer
Solution
Step 1: Use correct named slot syntax with default content
Named slots require name attribute and default content inside the slot tags.
Step 2: Verify all slots have names and defaults
Default Header
Default Content
Default Footer correctly names all slots and provides default text inside each slot tag.