How do Svelte stores work?
Assesses fundamental understanding of Svelte conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
A Svelte store is any object with a subscribe method that calls a callback with the current value and returns an unsubscribe function. The built-in writable, readable and derived helpers cover most cases.
import { writable, derived } from 'svelte/store';
export const count = writable(0);
export const doubled = derived(count, $c => $c * 2);
count.update(n => n + 1);
Inside a component you prefix a store with $ to read its value, so $count gives the current number, and Svelte subscribes and unsubscribes automatically. readable takes a start function that returns a cleanup and is useful for subscriptions such as time or sockets. derived can combine several stores and supports an async callback.
Custom stores wrap writable and expose domain methods such as increment, which keeps mutation rules in one place. Stores remain useful for cross-component state and for interop, while Svelte 5 runes in a shared module can replace them for new code.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.