All interview guides

Svelte Interview Questions and Answers

24 questions that come up in Svelte technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is SvelteKit?

Advanced

Answer: Full-stack framework built on Svelte

SvelteKit is full-stack framework. File-based routing, SSR, SSG, API routes, adapters for deployment. Like Next.js for React. Batteries included. Production-ready.

2. What are Svelte stores?

Intermediate

Answer: Reactive values accessible across components

Stores provide reactive state outside components. writable, readable, derived. Import and subscribe. Auto-unsubscribe in components. Simple state management.

3. What is Svelte?

Beginner

Answer: Compiler that converts components to efficient JavaScript

Svelte is a compiler, not a framework. It compiles components to highly efficient imperative code at build time. No virtual DOM. Truly reactive. Less code, better performance.

4. What is file-based routing in SvelteKit?

Advanced

Answer: Routes defined by file structure in src/routes

src/routes/about/+page.svelte → /about. Dynamic: [id]/+page.svelte. Layouts: +layout.svelte. API routes: +server.js. Convention over configuration. Intuitive structure.

5. What makes Svelte different from React/Vue?

Beginner

Answer: Compile-time framework, no virtual DOM, truly reactive

Svelte compiles to vanilla JS at build time. No runtime overhead. No virtual DOM diffing. Truly reactive - updates DOM surgically. Smaller bundle sizes. Write less code.

6. What is a writable store?

Intermediate

Answer: Store with set and update methods

writable(initialValue) creates store. set(newValue) replaces. update(fn) modifies. subscribe(callback) listens. Use $store for auto-subscribe. Most common store type.

7. How do you declare a reactive variable?

Beginner

Answer: let count = 0;

Just use let: let count = 0. Svelte compiler makes it reactive. Assignments trigger updates: count += 1. No setState, no refs. Simple JavaScript.

8. What is a readable store?

Intermediate

Answer: Store that cannot be set from outside

readable(initialValue, start) creates read-only store. Value set internally. Use for time, location, external data. Subscribers can read, not write. Controlled updates.

9. How do you display a variable in the template?

Beginner

Answer: {variable}

Use single curly braces: {count}. Any JavaScript expression works: {count * 2}. Auto-escapes HTML. Use {@html} for unescaped HTML (dangerous).

10. What is a derived store?

Intermediate

Answer: Store computed from other stores

derived(stores, callback) computes from other stores. Auto-updates when dependencies change. Like computed properties. Can depend on multiple stores. Efficient caching.

11. What is +page.js/ts?

Advanced

Answer: Load function for page data

+page.js exports load function. Runs server and client. Fetches data for page. export async function load({ params }) {}. Returns data as props. SSR-compatible.

12. How do you handle a click event?

Beginner

Answer: on:click={handler}

Use on: directive: <button on:click={increment}>. Inline: on:click={() => count++}. Event modifiers: on:click|preventDefault. No need to bind this.

13. What is the $ prefix for stores?

Intermediate

Answer: Auto-subscribe in components

$store auto-subscribes and unsubscribes. Use anywhere in component: {$count}. No manual subscribe/unsubscribe. Compiler feature. Very convenient.

14. What is +layout.svelte?

Advanced

Answer: Wraps child routes

+layout.svelte wraps child routes. <slot /> renders child. Nested layouts. Shared UI: nav, footer. Can have +layout.js for layout data. Hierarchical.

15. What is reactivity in Svelte?

Beginner

Answer: Assignments trigger DOM updates automatically

Reactivity: assignments trigger updates. count = count + 1 updates DOM. Compiler instruments code. No virtual DOM diffing. Surgically updates changed parts only.

16. What is +server.js/ts?

Advanced

Answer: API endpoint handler

+server.js exports HTTP method handlers: GET, POST, etc. API routes. export async function GET() { return json(data); }. Full backend in same project.

17. What is onMount lifecycle?

Intermediate

Answer: Runs after component first renders

onMount(callback) runs after component mounts. Use for DOM access, API calls, subscriptions. Return cleanup function. Runs in browser only, not SSR.

18. What is load function?

Advanced

Answer: Fetches data before page renders

load runs before rendering. Server and client. Access params, url, fetch. Return data as props. Automatic serialization. SSR-aware. Essential for data loading.

19. What is onDestroy lifecycle?

Intermediate

Answer: Runs before component is destroyed

onDestroy(callback) runs before component destroyed. Clean up: timers, subscriptions, listeners. Automatically called with onMount return. Essential for memory management.

20. How do you create a reactive statement?

Beginner

Answer: $: statement

$: marks reactive statement: $: doubled = count * 2. Re-runs when dependencies change. Like computed properties. Can have multiple. Use for derived values.

21. How do you define props?

Beginner

Answer: export let propName;

Export variables as props: export let name; export let age = 18. Default values supported. Use: <Child name="John" age={30} />. Simple and intuitive.

22. What is the difference between universal and server load?

Advanced

Answer: Universal runs both sides, server runs server only

+page.js: universal load (both). +page.server.js: server-only load. Server-only for secrets, database. Universal for API calls. Choose based on needs.

23. What is beforeUpdate lifecycle?

Intermediate

Answer: Runs before DOM updates

beforeUpdate(callback) runs before DOM updates. Access old DOM state. Schedule work before render. Use sparingly - usually unnecessary. Timing-sensitive operations.

24. What is afterUpdate lifecycle?

Intermediate

Answer: Runs after DOM updates

afterUpdate(callback) runs after DOM updates. Access new DOM state. Sync DOM with state. Use for scroll position, measurements. Runs every update.

Ready to test yourself?

The full Svelte bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the Svelte quiz