Svelte · Junior · Question 44 of 76
What does the $ prefix do with a store in a component?
<script>
import { count } from "./stores.js";
</script>
<p>{$count}</p>- ✓Correct answer: Subscribes to the store, reads its current value and unsubscribes when the component is destroyed
- 2Creates a copy of the store
- 3Marks the store as deprecated
Explanation
Assigning $count = 1 calls count.set(1) on a writable store. The store must be declared at the top level of the component.