Recall & Review
beginner
What is a reactive declaration in Svelte using
let?A reactive declaration in Svelte is a way to automatically update a variable when its dependencies change. It uses the
$: label before a statement to make it reactive.Click to reveal answer
beginner
How do you write a reactive declaration that updates
total when price or quantity changes?You write: <br>
$: total = price * quantity;<br>This means whenever price or quantity changes, total updates automatically.Click to reveal answer
intermediate
Can reactive declarations in Svelte run statements other than assignments?
Yes. Reactive declarations can run any statement, like function calls or console logs, as long as they start with
$:. For example, $: console.log(count); runs whenever count changes.Click to reveal answer
beginner
What happens if you use a reactive declaration with a variable that does not change?
The reactive declaration runs once when the component initializes. If the variable never changes, it won't run again.
Click to reveal answer
beginner
Why are reactive declarations useful in Svelte?
They let you write simple code that automatically updates values or runs code when data changes, without manually writing event handlers or watchers.Click to reveal answer
What symbol starts a reactive declaration in Svelte?
✗ Incorrect
Reactive declarations in Svelte always start with the
$: label.Which of these will update automatically when
count changes?<br>1) $: double = count * 2;<br>2) let double = count * 2;✗ Incorrect
Only the reactive declaration with
$: updates automatically when count changes.Can you use reactive declarations to run a function when a variable changes?
✗ Incorrect
Reactive declarations can run any statement, including function calls, when dependencies change.
What happens if a reactive declaration depends on multiple variables?
✗ Incorrect
Reactive declarations update whenever any of their dependent variables change.
Which is a correct reactive declaration to log
count whenever it changes?✗ Incorrect
The correct syntax is
$: console.log(count); to reactively run code on count changes.Explain how reactive declarations work in Svelte and give an example.
Think about how Svelte tracks variables and updates values automatically.
You got /3 concepts.
Describe a situation where using a reactive declaration is better than manually updating a variable.
Consider how reactive declarations reduce manual work and bugs.
You got /3 concepts.