If Statements in Svelte
Just like in React, templates in Svelte can also handle conditional statements:
Copied to clipboard!
{#if user.isAdmin}
<h1>Welcome to the World βοΈ</h1>
{:else if user.isEditor}
<h1>Welcome to the Library π«</h1>
{:else}
<h1>Welcome to the Jungle π¦οΈ</h1>
{/if}
These blocks can have optional else-if
and else
blocks.
Resources:
π More Webtips
Master the Art of Frontend
- Access 100+ interactive lessons
- Unlimited access to hundreds of tutorials
- Prepare for technical interviews