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}

Explanation

It's allowed only as the immediate child of blocks like {#each}, {#if}, {:then}, {#snippet} or a component.

Further reading

Problem with a question

Svelte · Junior · question 62

Test yourself

Take the Svelte · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz