0 day streak
javascript / beginner
Snippet

Conditional Rendering

The {#if} block is used to conditionally render parts of your UI based on whether an expression is truthy or falsy.

snippet.js
javascript
1
2
3
4
5
6
7
8
9
<script>
let visible = true;
</script>
{#if visible}
<p>Now you see me!</p>
{:else}
<p>Now you don't!</p>
{/if}
svelte
Breakdown
1
{#if visible}
Checks if 'visible' is true to render the following block.
2
{:else}
Provides an alternative block to render if the condition is false.