[{"id":"svelteadvanced-001","courseId":"svelte-advanced","domain":"reactivity-state","topic":"Tracking context with $effect.tracking","prompt":"An effect calls a helper function, and the helper reads a $state variable named price inside its body. Later, price changes. What happens to the effect?","hint":"Consider how far the tracking reaches once the effect's function is running.","explain":"When an effect runs, Svelte records each reactive value it reads during that run. Reads can be direct, or they can happen inside other functions the effect calls.","source":"https://svelte.dev/docs/svelte/$effect#$effect.tracking","interaction":{"type":"single"},"options":[{"id":"a","text":"It re-runs, because the helper's read happens during the effect's run","why":"Reads made by functions the effect calls are tracked too, since they happen synchronously while the effect runs."},{"id":"b","text":"It does not re-run; only state read directly in the effect body counts","whyNot":"Tracking covers indirect reads through function calls, not just reads written directly in the body."},{"id":"c","text":"It re-runs only if the helper is also declared with $effect","whyNot":"Helpers need no special declaration; any state read during the effect's run is tracked."},{"id":"d","text":"It stays put until user code calls the effect again","whyNot":"A change to tracked state schedules a re-run by itself; nothing has to call the effect."}],"answer":"a","explanation":"An effect tracks every reactive value read synchronously during its run, including reads made inside functions it calls, and re-runs when they change.","concept":"An effect tracks every reactive value read synchronously during its run, including reads made inside functions it calls, and re-runs when they change.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Anything an effect reads synchronously, even inside a helper, becomes a dependency."]},{"id":"svelteadvanced-002","courseId":"svelte-advanced","domain":"reactivity-state","topic":"Pending async work with $effect.pending","prompt":"An $effect that reads a $state value before its first await re-runs when that value later changes.","hint":"Consider which part of the effect's function is running when the read happens.","explain":"An effect's dependencies are whatever it reads while its function is running, including reads made inside helper functions it calls. A function that pauses partway can resume later, after its run has ended.","source":"https://svelte.dev/docs/svelte/$effect#$effect.pending","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"A read made before the first await runs synchronously, so it is tracked and a later change schedules another run."},{"id":"b","text":"False","whyNot":"A read made before the first await runs synchronously, so it is tracked like any other read in the run."}],"answer":"a","explanation":"Only values read synchronously during an effect's run become dependencies; values read after an await are not tracked.","concept":"Only values read synchronously during an effect's run become dependencies; values read after an await are not tracked.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Read every dependency before the first await in an effect, or it will not re-run for that value."]},{"id":"svelteadvanced-003","courseId":"svelte-advanced","domain":"reactivity-state","topic":"Svelte features by release","prompt":"Put these Svelte additions in the order their releases introduced them, earliest first.","hint":"Compare the release numbers that each reference entry records.","explain":"Framework features ship in numbered releases, and later releases add things earlier ones lacked. Each reference entry records the release that introduced it.","source":"https://svelte.dev/docs/svelte/svelte","interaction":{"type":"sort","items":[{"text":"Pass outro: true to unmount() so transitions play before removal","why":"The outro option has applied since 5.13.0, so transitions play before the component is removed."},{"text":"Await settled() to wait for state changes and the async work they start","why":"settled() is available from 5.36 and resolves once those changes, their async work and the DOM update are done."},{"text":"Create a typed context triplet with createContext()","why":"createContext() is available from 5.40.0 and returns get, set and has functions."},{"text":"Create a fork() to evaluate state changes without applying them to the DOM","why":"fork() is tagged 5.42, the newest release among these four."}]},"options":[],"answer":"o:abcd","explanation":"The Svelte reference records the release that introduced each API or option, so ordering these by release number gives the order they arrived.","concept":"The Svelte reference records the release that introduced each API or option, so ordering these by release number gives the order they arrived.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Svelte's reference tags each API or option with the release that introduced it."]},{"id":"svelteadvanced-004","courseId":"svelte-advanced","domain":"reactivity-state","topic":"Tracing causes with $inspect.trace","prompt":"A component's effect calls $inspect.trace('cart') as its first line, then recalculates totals. In development, a state change makes the effect run again. What does the trace print?","hint":"Think about what a tracer is for when a function runs more often than you expected.","explain":"A debugging aid can be attached to a function so it reports on each later run, not just the first. Consider what would make such a report useful when work repeats unexpectedly.","source":"https://svelte.dev/docs/svelte/$inspect","interaction":{"type":"single"},"options":[{"id":"a","text":"The reactive values whose changes caused this re-run","why":"$inspect.trace logs which pieces of reactive state caused the effect to fire."},{"id":"b","text":"A dump of every $state value in the component on each run","whyNot":"The trace names the state that caused the re-run; it does not snapshot all state."},{"id":"c","text":"Nothing, because it only logs in production builds","whyNot":"$inspect only works during development; in a production build it becomes a no-op."},{"id":"d","text":"A count of how many times the effect has run so far","whyNot":"The trace reports the causes of each re-run; it does not keep a run counter."}],"answer":"a","explanation":"In development, $inspect.trace() logs which pieces of reactive state caused each re-run of the effect or derived it sits in.","concept":"In development, $inspect.trace() logs which pieces of reactive state caused each re-run of the effect or derived it sits in.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"$effect(() => {\n  $inspect.trace('cart');\n  recalculate();\n});","takeaways":["Place $inspect.trace() as the first statement of the function you want to debug; it logs only in development."]},{"id":"svelteadvanced-005","courseId":"svelte-advanced","domain":"reactivity-state","topic":"Custom logging with $inspect().with","prompt":"A developer writes $inspect(count).with(fn) to customise $inspect output in development. Which TWO statements about this method are correct?","hint":"Think about what the callback receives and what it replaces.","explain":"A logging helper can be swapped for your own handler, which receives the same details the helper would have shown. Think about what a handler needs in order to tell a first report from a later one.","source":"https://svelte.dev/docs/svelte/$inspect","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The callback you pass is called instead of console.log","why":"With .with(), your callback receives the output in place of console.log."},{"id":"b","text":"Its first argument is either 'init' or 'update'","why":"The first argument says whether it is the initial report or a later change; the inspected values follow it."},{"id":"c","text":"The callback receives a stack trace as its first argument","whyNot":"The first argument is 'init' or 'update'; the inspected values come after it."},{"id":"d","text":"It also runs in production builds, since it replaces logging","whyNot":"$inspect becomes a no-op in production builds, so the callback never runs there."},{"id":"e","text":"Calling .with() stops $inspect from tracking nested values","whyNot":"$inspect still tracks state deeply; .with() changes only what happens on each report."},{"id":"f","text":"The callback runs once at init and never on later updates","whyNot":"The callback is also invoked with 'update' whenever the inspected values change."}],"answer":"ab","explanation":"$inspect(...).with(fn) calls fn instead of console.log, passing 'init' or 'update' first, then the inspected values.","concept":"$inspect(...).with(fn) calls fn instead of console.log, passing 'init' or 'update' first, then the inspected values.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Use .with() to route $inspect output to your own handler, branching on the first argument."]}]