Svelte · Junior · Question 11 of 76
How do you declare a value computed from other state?
let count = $state(2);
let doubled = $derived(count * 2);- ✓Correct answer: With
$derived(expression); it recalculates when the state it reads changes - 2With a plain
let doubled = count * 2 - 3With
$effect(() => doubled = count * 2)
Explanation
Component code runs once on creation, so a plain let would keep the initial value. Updating state inside $effect for this is an anti-pattern.