0
0
Svelteframework~20 mins

Slot basics (default slot) in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Slot Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Svelte component with a default slot?

Consider the following Svelte component usage:

<Card>Hello, world!</Card>

And the Card.svelte component code:

<div class="card">
  <slot>Default content</slot>
</div>

What will be rendered inside the <div>?

Svelte
<div class="card">
  <slot>Default content</slot>
</div>
AThe text 'Hello, world!' inside the div
BThe text 'Default content' inside the div
CAn empty div with no text
DA runtime error because slot is missing
Attempts:
2 left
💡 Hint

Think about what happens when you put content between component tags and the component has a default slot.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a default slot in Svelte?

Choose the correct syntax to create a default slot with fallback content 'Loading...'.

A<slot>Loading...</slot>
B<slot name="default">Loading...</slot>
C<slot fallback="Loading..."></slot>
D<slot default>Loading...</slot>
Attempts:
2 left
💡 Hint

Default slots do not need a name attribute.

state_output
advanced
2:00remaining
What will be the output when slot content changes dynamically?

Given this parent component:

<script>
  import Card from './Card.svelte';
  let message = 'Hello';
  setTimeout(() => message = 'Goodbye', 1000);
</script>

<Card>{message}</Card>

And Card.svelte:

<div class="card">
  <slot>Default</slot>
</div>

What will the user see after 2 seconds?

AThe text 'Default' inside the div
BThe text 'Hello' inside the div
CAn empty div with no text
DThe text 'Goodbye' inside the div
Attempts:
2 left
💡 Hint

Slots update reactively when the parent content changes.

🔧 Debug
advanced
2:00remaining
Why does this slot fallback content never show?

Look at this component usage:

<Wrapper></Wrapper>

And the component code:

<div>
  <slot>Fallback content</slot>
</div>

Why does 'Fallback content' never appear?

ABecause fallback content is ignored in Svelte slots
BBecause the parent component always passes empty content, so slot is considered filled
CBecause fallback content only shows if no content is passed between tags, but empty content counts as content
DBecause the slot tag is missing a name attribute
Attempts:
2 left
💡 Hint

Think about what counts as 'no content' for a slot fallback.

🧠 Conceptual
expert
3:00remaining
How does Svelte handle default slot content when nested components are involved?

Consider these components:

// Parent.svelte
<Child>Parent content</Child>
// Child.svelte
<slot>Child default</slot>
// Grandchild.svelte
<slot>Grandchild default</slot>

If Child.svelte uses <Grandchild></Grandchild> inside its slot, what will be rendered?

AThe text 'Parent content' replaces Child's slot, and Grandchild's default slot shows 'Grandchild default'
BThe text 'Parent content' replaces Child's slot, and Grandchild's slot is empty so fallback 'Grandchild default' shows
CThe text 'Parent content' replaces Child's slot, and Grandchild's slot is replaced by 'Parent content' again
DOnly 'Child default' is shown because Parent content is ignored
Attempts:
2 left
💡 Hint

Remember how slots pass content down and fallback content works at each level.