Svelte Interview Questions and Answers
Svelte 5 and runes ($state, $derived, $effect, $props), templates and snippets, reactivity without a virtual DOM, SvelteKit: routing, load, form actions and SSR.
226 questions for Svelte interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.
- Runes
- Reactivity
- Snippets
- SvelteKit
- SSR
Questions by level
Junior
Core concepts and syntax · 50 questions
Middle
Practice, nuances and optimization · 50 questions
Senior
Architecture, internals, edge cases · 50 questions
Sample questions
A few questions from each level with the correct answer and an explanation.
Svelte · Junior
- What is Svelte?
Correct answer: A UI framework that is mainly a compiler: components are turned into JavaScript that updates the DOM directly
Svelte does most of its work at build time. The output is small, framework-light code that changes exactly the DOM nodes that depend on changed state, without a virtual DOM.
- What is SvelteKit?
Correct answer: The official application framework for Svelte: routing, data loading, SSR, forms and deployment adapters, built on Vite
Svelte is the component layer; SvelteKit adds what a full app needs, similar to Next.js for React or Nuxt for Vue.
- What is the recommended way to create a new SvelteKit project?
Correct answer:
npx sv create my-appsvis the official Svelte CLI. It scaffolds the project and can add integrations like TypeScript, ESLint, Vitest or Playwright. - What can a
.sveltefile contain?Correct answer: A
<script>block, markup and a<style>block, all optionalA component can have several top-level elements. There is also
<script module>, which runs once when the module is evaluated rather than for each instance.
Svelte · Middle
- What is the difference between
$effectand$effect.pre?Correct answer:
$effect.preruns before DOM updates (e.g. to save scroll position);$effectruns after the DOM is updated$effect.prereplacesbeforeUpdatefrom Svelte 4, and$effectreplacesafterUpdate. - Why doesn't
items.set(k, v)update the UI whenitemsis a plainMapin$state?Correct answer:
$stateonly proxies plain objects and arrays; useSvelteMapfromsvelte/reactivitysvelte/reactivityalso hasSvelteSet,SvelteDate,SvelteURL,SvelteURLSearchParamsandMediaQuery. Their values aren't made deeply reactive. - What does
$inspect.trace()help with?Correct answer: Placed as the first line of
$effector$derived.by, it logs which dependency triggered the re-runUseful when something updates too often or not at all. Like
$inspect, it does nothing in production. - What is an advantage of snippets over Svelte 4 slots?
Correct answer: They are values: you can pass parameters, pass them as props, type them with
Snippet<[T]>and reuse them in the same componentTop-level snippets can even be referenced inside
<script>, and exported from<script module>if they don't use component state.
Svelte · Senior
- What model does Svelte 5 reactivity use under the hood?
Correct answer: Signals: reading state inside an effect or derived registers a dependency, writing it schedules only the affected effects
Template expressions are effects too. Runes are the syntax over this runtime; Svelte 4 instead relied on the compiler instrumenting assignments.
- Why did Svelte 5 move from compiler-instrumented
letreactivity to runes?Correct answer: Svelte 4 reactivity worked only at the top level of components and was hard to reason about; runes make reactivity explicit and work in
.svelte.jsfiles and classesWith
$:statements dependencies were determined statically and only at compile time; runes track them at runtime, including through function calls. - How are
$derivedvalues evaluated?Correct answer: Lazily and memoized: recalculated only when read after a dependency changed, and downstream updates are skipped if the result is the same
Svelte uses push-pull reactivity: changes mark dependents dirty (push), values are recomputed on read (pull). Equal results don't propagate.
- What is the cost of deep
$stateproxies, and how do you control it?Correct answer: Every property access goes through a proxy and nested objects are wrapped lazily; for large immutable data use
$state.rawor plain variablesOnly use
$statefor values that drive effects, deriveds or the template. Non-reactive data can stay in normal variables.
Combined quizzes with this topic
Questions from several topics at once - just like an interview for a specific role.
Coding tasks
Write your solution right in the browser, and tests check it instantly. Interview classics: debounce, throttle, deepClone, Promise.all, EventEmitter, an LRU cache and more.
Open tasks →