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>- ✓Correct answer:
2 / 0:doubledwas computed once and isn't reactive - 2
2 / 4 - 3An error:
countcan't be changed
Explanation
Script code runs once. To keep doubled in sync use $derived(count * 2).