Skip to main content
InterviewHubPRO
Section Overview
Q15

Question 15 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

30%
Svelte & SvelteKit (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

Snippets in Svelte 5 (`{#snippet}` vs. Legacy `<slot>`).

senior LevelCode ExampleSystem DesignSvelte 5

In Simple Words: In Svelte 4, template composition relied on <slot> elements, which had limited scoping and typing. In Svelte 5, Snippets treat template chunks as first-class reusable functions:

svelte
<!-- Declaration -->
{#snippet userRow(user, index)}
  <div class="row">
    <span>#{index}</span>
    <strong>{user.name}</strong>
  </div>
{/snippet}

<!-- Invocation -->
{@render userRow({ name: 'Alice' }, 1)}
{@render userRow({ name: 'Bob' }, 2)}