[{"id":"sveltebeginner-001","courseId":"svelte-beginner","domain":"reactivity-state","topic":"Taking a snapshot of $state","prompt":"A component declares `let counter = $state({ count: 0 });` and must hand its value to a charting library. The library rejects Svelte's proxies. What should the component pass?","hint":"Think about a rune built to make a static copy of reactive values, not one that declares new state.","explain":"Svelte wraps plain objects in a layer that watches every read and write. Outside code may reject that layer, so a component sometimes needs to hand over something else built from its data.","source":"https://svelte.dev/docs/svelte/$state#$state.snapshot","interaction":{"type":"single"},"options":[{"id":"a","text":"counter itself, since the library can read the proxy like any object","whyNot":"The page says a $state object is a proxy, and a snapshot is handy when an external API doesn't expect one."},{"id":"b","text":"$state.snapshot(counter), a static copy without the proxy","why":"$state.snapshot takes a static snapshot of a deeply reactive proxy, which suits APIs that don't expect one."},{"id":"c","text":"counter.count, the plain number stored inside it","whyNot":"That passes one number; it does not give the library the object at all."},{"id":"d","text":"$state.eager(counter), which removes the proxy","whyNot":"$state.eager shows a state change in the UI before a pending await settles; it is not for unwrapping."}],"answer":"b","explanation":"$state.snapshot takes a static snapshot of a deeply reactive $state proxy, for passing state to an external library or API that doesn't expect a proxy.","concept":"$state.snapshot takes a static snapshot of a deeply reactive $state proxy, for passing state to an external library or API that doesn't expect a proxy.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"<script>\n  let counter = $state({ count: 0 });\n</script>","takeaways":["Use $state.snapshot to hand reactive state to code that doesn't expect a proxy."]},{"id":"sveltebeginner-002","courseId":"svelte-beginner","domain":"reactivity-state","topic":"Mutating object properties in state","prompt":"A component has `let todos = $state([{ done: false, text: 'eat lunch' }]);` and renders each todo. Which TWO statements about changing these todos are correct?","hint":"Think about how far Svelte wraps the value you pass to $state, and what a copy of a property holds.","explain":"Svelte wraps plain arrays and objects in a proxy that sees each read and write. The wrapping goes as deep as the plain structure does; class instances are left unwrapped.","source":"https://svelte.dev/docs/svelte/$state#Deep-state","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Only the outer array is reactive; the objects inside it stay plain","whyNot":"Svelte proxies recursively, so the objects inside an array or simple object are reactive too."},{"id":"b","text":"Setting todos[0].done = true updates any UI that reads todos[0].done","why":"Property writes on a state proxy are tracked, so only the UI that reads that property updates."},{"id":"c","text":"let { done } = todos[0] stays linked, so later changes to done show up","whyNot":"Destructuring reads the value at that point; the variable done does not follow later changes."},{"id":"d","text":"An object pushed with todos.push(...) is made reactive too","why":"Array methods like push are tracked, and the new object is proxified like the others."},{"id":"e","text":"Changing todos[0].done does nothing until todos is assigned a new array","whyNot":"Property changes are tracked on their own; reassigning the whole array is not needed."},{"id":"f","text":"Changing a property edits the plain object that was first passed to $state","whyNot":"Updating a property of a proxy does not mutate the original object."}],"answer":"bd","explanation":"Arrays and plain objects in $state become deeply reactive proxies: property writes and array methods such as push are tracked, and the original object is not mutated.","concept":"Arrays and plain objects in $state become deeply reactive proxies: property writes and array methods such as push are tracked, and the original object is not mutated.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"<script>\n  let todos = $state([\n    { done: false, text: 'eat lunch' }\n  ]);\n</script>","takeaways":["Destructured values are copies: they stop following later changes to the state they came from."]},{"id":"sveltebeginner-003","courseId":"svelte-beginner","domain":"reactivity-state","topic":"Computing values with $derived","prompt":"A $state value that a $derived reads gets a new value. Put these steps of how Svelte propagates that change in the order they happen.","hint":"Think about what happens the instant a value changes, and what waits until someone reads it.","explain":"A change travels through a chain of dependent values in two kinds of passes. One kind runs eagerly at the moment of change; the other runs lazily, only on demand.","source":"https://svelte.dev/docs/svelte/$derived","interaction":{"type":"sort","items":[{"text":"The state a $derived reads is reassigned.","why":"Every change starts with a plain assignment to the state the derived depends on."},{"text":"Everything that depends on it is notified straight away.","why":"The notification goes out at once, so dependents know a change happened before any value is recomputed."},{"text":"The derived waits and is not recalculated until something reads it.","why":"Recalculation is deferred until a read, so the derived is re-evaluated only when it is needed."},{"text":"When read, it recalculates; an identical result skips downstream updates.","why":"If the new derived value equals the previous one, updates further down the chain are skipped."}]},"options":[],"answer":"o:abcd","explanation":"A $derived is updated lazily: a change notifies its dependents at once, but it is recalculated only when next read, and an unchanged result skips downstream updates.","concept":"A $derived is updated lazily: a change notifies its dependents at once, but it is recalculated only when next read, and an unchanged result skips downstream updates.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Svelte notifies dependents at once but recalculates a $derived only when it is read."]},{"id":"sveltebeginner-004","courseId":"svelte-beginner","domain":"reactivity-state","topic":"Running side effects with $effect","prompt":"This effect reads count inside a timer callback. Judge the statement: the effect re-runs whenever count changes.","hint":"Think about when the callback that reads count runs, compared with the effect body.","explain":"An effect re-runs when the reactive values it reads during its own run change. The list of those values is built while the run happens, so when a read takes place matters.","source":"https://svelte.dev/docs/svelte/$effect","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The effect is not re-run by count changes, because reads made inside setTimeout are not tracked."},{"id":"b","text":"False","why":"Only state read synchronously in the effect body is tracked; a read inside setTimeout is skipped."}],"answer":"b","explanation":"$effect tracks only state read synchronously in its body, including through function calls; values read after an await or inside setTimeout are not tracked.","concept":"$effect tracks only state read synchronously in its body, including through function calls; values read after an await or inside setTimeout are not tracked.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"<script>\n  let count = $state(0);\n\n  $effect(() => {\n    setTimeout(() => {\n      console.log(count);\n    }, 1000);\n  });\n</script>","takeaways":["An effect depends only on state it reads synchronously during its run."]},{"id":"sveltebeginner-005","courseId":"svelte-beginner","domain":"reactivity-state","topic":"Raw state with $state.raw","prompt":"A component uses `let person = $state.raw({ name: 'Heraclitus', age: 49 });` and a button runs `person.age += 1;`. What does the UI show after the click?","hint":"Think about whether raw state tracks changes inside the object or only changes to the whole value.","explain":"Svelte can wrap an object so that each property write is seen, or leave it unwrapped to save work on large data. Each choice changes what kind of update counts as a change.","source":"https://svelte.dev/docs/svelte/$state#$state.raw","interaction":{"type":"single"},"options":[{"id":"a","text":"The new age appears, because $state.raw still tracks properties of the object","whyNot":"Raw state is not made deeply reactive, so a property write is not seen by the UI."},{"id":"b","text":"No visible change; the UI updates only when person is reassigned to a new object","why":"Raw state cannot be mutated, so a property write has no effect; you replace the whole object."},{"id":"c","text":"The new age is queued and shown on the next mount of the component","whyNot":"Nothing is queued; the property write simply has no effect on the UI."},{"id":"d","text":"Svelte throws a compile error, since raw state forbids property writes","whyNot":"The page says the write has no effect; it describes no compile error for it."}],"answer":"b","explanation":"$state.raw is not deeply reactive: it cannot be mutated, so only reassigning the whole value updates the UI, which avoids proxy cost for large data.","concept":"$state.raw is not deeply reactive: it cannot be mutated, so only reassigning the whole value updates the UI, which avoids proxy cost for large data.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"<script>\n  let person = $state.raw({\n    name: 'Heraclitus',\n    age: 49\n  });\n\n  function birthday() {\n    person.age += 1;\n  }\n</script>","takeaways":["Use $state.raw for large data you replace rather than mutate; reassign to update it."]}]