Svelte & SvelteKit (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
Control Flow in Svelte Templates: `{#if}`, `{#each}`, and `{#await}`.
junior LevelCode ExampleComponentsAsync & PromisesSvelte 5
In Simple Words: Svelte provides clean declarative template blocks:
svelte
<!-- Conditional rendering -->
{#if status === 'loading'}
<Spinner />
{:else if status === 'error'}
<ErrorMessage />
{:else}
<Dashboard />
{/if}
<!-- List iteration with unique key -->
{#each users as user (user.id)}
<li>{user.name}</li>
{:else}
<p>No users found.</p>
{/each}
<!-- Direct Promise resolution in template -->
{#await fetchUserData()}
<p>Loading profile...</p>
{:then data}
<h1>Welcome {data.name}</h1>
{:catch error}
<p>Failed to load: {error.message}</p>
{/await}