Svelte and SvelteKit interview questions and answers
Svelte interview questions test whether you understand that Svelte is a compiler: it turns components into code that updates the DOM directly, with no virtual DOM to diff. Expect questions on reactivity in both styles, the runes of Svelte 5 ($state, $derived, $effect, $props) and the older let and $: syntax, stores, bindings, keyed each blocks, snippets, and for full-stack roles SvelteKit load functions, form actions and rendering modes.
By Evin JohnPublished 7 min read
How Svelte comes up in interviews
Svelte roles are fewer than React roles, so interviewers often probe two things: whether you really know Svelte's model rather than translating React habits, and whether you can work across versions. Svelte 5 introduced runes, and many production apps still run Svelte 4 code or a mix during migration. A typical loop has a concept screen, a small build (a filterable list, a form with validation, a component with a slot or snippet), and for SvelteKit jobs a conversation about where data loads and what runs on the server.
- Concept screenWhat the compiler does, how reactivity is triggered, props, events and bindings. Expect a short code reading question.
- Build exerciseA component or small page in a sandbox or the Svelte playground, usually 45 to 60 minutes, with state, a derived value and a list.
- SvelteKit discussionRoutes, load functions, form actions, cookies and auth in hooks, and choosing SSR, CSR or prerendering per page.
Fundamentals
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What does it mean that Svelte is a compiler? | Core model | Components are compiled at build time into JavaScript that creates and updates DOM nodes directly. There is no virtual DOM diff at runtime, which keeps bundles small and updates targeted. |
| What are the parts of a .svelte file? | Structure | A script block for logic, optional module-level script, markup with template syntax, and a style block whose CSS is scoped to the component by default. |
| How is CSS scoped and how do you escape it? | Styling | The compiler adds a generated class to the component's elements and rewrites selectors to match. :global() opts a selector out when you need to style child or third-party markup. |
| How do you pass data down and events up? | Component API | Props go down. In Svelte 5, callbacks are passed as props, such as an onselect function; Svelte 4 used createEventDispatcher and on: directives. Both versions support two-way bind: for form-like props. |
| Why add a key to an each block? | Lists | Without a key, Svelte updates items by position, so removing the first row can leave the wrong state or transition on the others. {#each items as item (item.id)} ties DOM nodes to items. |
| What does bind:value do? | Bindings | Keeps an input and a variable in sync both ways. bind:this gives a reference to the DOM element, useful for focusing or measuring. |
| What is an action (use:)? | DOM behavior | A function that runs when an element is mounted and can return update and destroy handlers. Good for tooltips, click-outside handling or wrapping a non-Svelte library. |
| How do transitions differ from animations in Svelte? | Motion | transition:, in: and out: run when an element enters or leaves the DOM. animate: runs when items in a keyed each block change position. |
Reactivity: runes and the older syntax
Expect at least one question comparing the two styles. Svelte 4 made top-level let variables reactive by tracking assignments, and used $: labels for derived values and side effects. Svelte 5 makes reactivity explicit with runes, which work the same way inside components and in .svelte.js modules.
<script>
let count = $state(0);
let doubled = $derived(count * 2);
$effect(() => {
document.title = `Clicked ${count} times`;
});
</script>
<button onclick={() => count++}>
{count} (doubled: {doubled})
</button><script>
let count = 0;
$: doubled = count * 2;
$: document.title = `Clicked ${count} times`;
</script>
<button on:click={() => count++}>
{count} (doubled: {doubled})
</button>- Why did `items.push(x)` not update the page in Svelte 4? Reactivity was triggered by assignment, and push mutates without assigning. The fix was
items = [...items, x]oritems.push(x); items = items. In Svelte 5, an array created with $state is a deep reactive proxy, so push works. - $derived versus $effect for computed values? Use $derived. It is pure, lazy and always consistent. Setting state from inside an effect to compute something creates extra updates and can loop.
- What is $derived.by for? Derived values that need more than one expression, such as filtering and then sorting. It takes a function, and the function's return value becomes the derived value.
- When does $effect run, and does it run on the server? After the component mounts and after the DOM updates when its dependencies change. It does not run during server rendering, which is why it is the right place for browser-only code.
- Why could the Svelte 4 version above crash in SvelteKit?
$:statements also run during server rendering, where document does not exist. Move browser-only code into onMount or guard it with the browser flag. - What do $state.raw and $state.snapshot do? raw makes a value reactive only on reassignment, which is cheaper for large objects you replace whole. snapshot gives a plain, non-proxied copy, for logging or passing to a library.
- How are props declared in Svelte 5? With
let { title, count = 0 } = $props();. A prop that a parent may bind to is marked with $bindable. - What replaced slots? Snippets: blocks of markup declared with #snippet and rendered with @render, which can take arguments and be passed as props. Slots still work in legacy mode.
- How do you migrate a Svelte 4 component? The official migration script converts most syntax. Components in both styles can coexist, so teams usually migrate file by file and fix the cases the script flags.
Sharing state: context and stores
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Context versus a store? | State scope | Context, set with setContext and read with getContext, is per component tree and safe for per-request data on the server. A module-level store is shared by everything that imports it, which on a server means shared across users. |
| What is the store contract? | Interop | Any object with a subscribe method that calls the subscriber with the current value right away and returns an unsubscribe function. Add set to make it writable. Anything meeting it works with the dollar-prefix auto-subscription. |
| What does the dollar prefix on a store do in a component? | Auto-subscription | It subscribes when the component mounts, unsubscribes when it is destroyed, and lets you read or assign the value as if it were a variable. |
| readable, writable and derived: when is each used? | Store types | writable for state code can set, readable for values that come from outside such as the time or a websocket, and derived for values computed from one or more stores. |
| Are stores still needed in Svelte 5? | Version judgment | They still work and suit streams of values. For shared app state, many teams now export $state objects from .svelte.js modules. Know both, and why a module-level object is still shared across server requests. |
function writable(value) {
const subscribers = new Set();
function set(next) {
if (Object.is(next, value)) return;
value = next;
for (const fn of subscribers) fn(value);
}
return {
subscribe(fn) {
subscribers.add(fn);
fn(value); // a new subscriber gets the current value at once
return () => { subscribers.delete(fn); };
},
set,
update: (fn) => set(fn(value)),
};
}
const count = writable(0);
const seen = [];
const stop = count.subscribe((v) => seen.push(v));
count.update((n) => n + 1);
count.set(1); // same value: no notification
stop();
count.set(5); // unsubscribed: not seen
console.log(seen); // [ 0, 1 ]SvelteKit and senior questions
import { error, fail } from '@sveltejs/kit';
export async function load({ params, fetch }) {
const res = await fetch(`/api/products/${params.id}`);
if (!res.ok) error(404, 'Product not found');
return { product: await res.json() };
}
export const actions = {
review: async ({ request, params }) => {
const data = await request.formData();
const text = String(data.get('text') ?? '').trim();
if (text.length < 10) return fail(400, { text, tooShort: true });
await saveReview(params.id, text);
return { saved: true };
},
};| Question | What it tests | What a strong answer shows |
|---|---|---|
| +page.js versus +page.server.js load? | Data loading | A universal load runs on the server for the first request and in the browser on client navigation, so it must not use secrets. A server load always runs on the server and can use the database and private environment variables. |
| Why use form actions instead of a fetch call? | Progressive enhancement | A plain form posts to the action and works without JavaScript. Adding use:enhance upgrades it to a client-side submit that updates the page without a full reload. |
| What goes in hooks.server.js? | Request handling | The handle hook runs on every request: read the session cookie, attach the user to locals, set headers, and decide whether to continue. handleError centralizes error logging. |
| How do you choose SSR, CSR or prerendering? | Rendering | Prerender pages that are the same for everyone, server render pages that need fresh or personal data and good first paint, and turn off SSR only for app-like pages that cannot run on the server. Each can be set per route. |
| What is an adapter? | Deployment | A build plugin that shapes the output for a target: Node server, static files, or a serverless or edge platform. Some features, such as streaming or long requests, depend on the target. |
| A page shows another user's data for a moment. Why? | Server state leak | Data was kept in a module-level variable or store on the server, which is shared across requests. Move per-user data into locals, load data or context. |
| The page flashes the wrong theme before hydrating. How do you fix it? | SSR and hydration | Store the preference in a cookie, read it in a server hook or load, and render the right class on the server instead of reading localStorage after mount. |
| When would Svelte not be your choice? | Judgment | When the team depends on a React-only library ecosystem or hiring pool. A good answer weighs bundle size and simplicity against ecosystem and team experience, without dismissing either side. |
Fictional example
- Interviewer
- You mentioned a Svelte 5 migration. How did you run it?
- Candidate
- Our dashboard had about eighty components in Svelte 4. We upgraded the packages first, kept everything in legacy mode, and confirmed the tests passed. Then we ran the migration script folder by folder, starting with leaf components. Most changes were mechanical, but the script flagged reactive statements with side effects, and those needed judgment: some became $derived, a few became $effect, and two turned out to be bugs that had been masking each other. We moved shared filters from a writable store to a $state object in a .svelte.js file, and kept the websocket feed as a readable store because it really is a stream. The whole thing took several sprints with no freeze on features.
A practice plan for Svelte interviews
- Rebuild one component in both syntaxes, Svelte 4 and Svelte 5 runes, and write down every difference you hit.
- Write the store contract from memory, then use your store with the dollar prefix in a component.
- Build a keyed list with add, remove and reorder, then remove the key and observe what breaks with a transition on each row.
- In SvelteKit, make one page with a server load, a form action with validation, use:enhance and an auth check in the handle hook.
- Try SSR, CSR and prerendering on three routes and explain the trade-off for each in a sentence.
- Do one timed mock build of an hour and one five-minute talk on when you would and would not pick Svelte.
Coming from React? React interview questions shows the hook-based model Svelte interviewers like to compare against, and Redux interview questions covers the store pattern that Svelte stores simplify. For the broader loop, see frontend developer interview questions.
Natively can help you rehearse as an AI interview assistant on Mac and Windows. Run a mock with a friend and it transcribes the session, so you can see whether you explained runes clearly or drifted into React terms. During practice it can read a Svelte task from a screenshot and suggest a starting structure, and on Pro or the free trial it uses your résumé and the job description to tailor suggestions. You can reopen past sessions and notes whenever you review.
Questions people ask
What Svelte questions are asked in interviews?
What the compiler does, reactivity with Svelte 5 runes and the older let and $: syntax, props, events and bindings, keyed each blocks, stores and context, snippets, transitions, and SvelteKit load functions, form actions and rendering modes.
What are runes in Svelte 5?
Compiler keywords that make reactivity explicit: $state for reactive values, $derived for computed values, $effect for side effects and $props for component inputs. They replace the assignment-based reactivity and $: statements of Svelte 4.
How is Svelte different from React?
Svelte compiles components into code that updates the DOM directly, with no virtual DOM diff at runtime, and tracks reactive values instead of re-running a whole component function on each state change.
What SvelteKit questions should I expect?
Universal versus server load functions, form actions with use:enhance, the handle hook and locals for auth, adapters for deployment, and when to choose SSR, CSR or prerendering for a route.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
