Svelte · Junior · Question 60 of 76

What does this code print when the button is clicked twice?

<script>
  let count = $state(0);
  let doubled = count * 2;
</script>

<button onclick={() => count++}>{count} / {doubled}</button>

Explanation

Script code runs once. To keep doubled in sync use $derived(count * 2).

Further reading

Problem with a question

Svelte · Junior · question 60

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