Svelte · Junior · Question 62 of 76
What does {@const} do?
{#each boxes as box}
{@const area = box.width * box.height}
<p>{box.width} × {box.height} = {area}</p>
{/each}- ✓Correct answer: Declares a local constant inside a block of markup
- 2Declares a global constant for the component
- 3Makes a value read-only in state
Explanation
It's allowed only as the immediate child of blocks like {#each}, {#if}, {:then}, {#snippet} or a component.