Recall & Review
beginner
What does the
$: symbol mean in Svelte?It marks a reactive statement that runs automatically whenever its dependencies change.
Click to reveal answer
beginner
How do reactive statements help in Svelte components?
They update values or run code automatically when related data changes, keeping the UI in sync without manual updates.
Click to reveal answer
beginner
Given <code>let count = 0;</code> and <code>$: doubled = count * 2;</code>, what happens when <code>count</code> changes?The variable
doubled updates automatically to twice the new count value.Click to reveal answer
intermediate
Can you use multiple reactive statements in one Svelte component?
Yes, you can have many
$: statements, each reacting to different variables or expressions.Click to reveal answer
intermediate
What happens if a reactive statement has no dependencies?
It runs once when the component initializes and never again, because nothing triggers it to rerun.
Click to reveal answer
What triggers a reactive statement marked with
$: to run in Svelte?✗ Incorrect
Reactive statements run automatically whenever any variable they depend on changes.
Which of these is a correct reactive statement syntax in Svelte?
✗ Incorrect
The correct syntax uses
$: followed by the statement without extra keywords.If you write
$: console.log(count);, when will the message print?✗ Incorrect
The reactive statement runs whenever
count changes, so it logs each time.Can reactive statements update other reactive statements in Svelte?
✗ Incorrect
Reactive statements can depend on variables updated by other reactive statements, creating chains.
What happens if you write
$: alert('Hello'); with no variables?✗ Incorrect
Without dependencies, the reactive statement runs once on initialization.
Explain how reactive statements ($:) work in Svelte and why they are useful.
Think about how Svelte updates values without you writing extra code.
You got /4 concepts.
Describe a simple example using a reactive statement to double a number when it changes.
Imagine you have a number and want another number always twice it.
You got /4 concepts.