Svelte Middle interview questions and answers
75 questions for a Svelte (Middle) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.When should you use
$derived.byinstead of$derived? - 2.Can you assign to a
$derivedvalue (Svelte 5.25+)? - 3.Which state does
$effecttrack as dependencies? - 4.Why is this an anti-pattern?
- 5.How do you read state inside
$effectwithout making it a dependency? - 6.What is the difference between
$effectand$effect.pre? - 7.When is
$state.rawa good choice? - 8.How do you make class fields reactive?
- 9.Why doesn't
items.set(k, v)update the UI whenitemsis a plainMapin$state? - 10.What does
$props()give you besides named props? - 11.Why does
colornot update when thetypeprop changes? - 12.What does
$inspect.trace()help with? - 13.How do you write reusable reactive logic (like a hook) in Svelte 5?
- 14.How do you pass named content areas (formerly named slots) to a component?
- 15.What is an advantage of snippets over Svelte 4 slots?
- 16.What is an attachment (
{@attach})? - 17.Why are attachments more flexible than actions?
- 18.What does a function binding do (Svelte 5.9+)?
- 19.Which bindings are read-only?
- 20.Why are transitions in Svelte local by default?
- 21.What is
Tween/Springinsvelte/motionused for? - 22.How do you make context reactive?
- 23.What does
createContext(Svelte 5.40+) give you? - 24.Why is module-level shared state risky in a SvelteKit app?
- 25.When do stores still make sense in Svelte 5?
- 26.What does
derivedfromsvelte/storedo? - 27.How do you mount a Svelte 5 component into the page manually?
- 28.What does
flushSync()fromsveltedo? - 29.How are Svelte components usually unit-tested?
- 30.How do you test an effect created outside a component?
- 31.How do you build a Svelte component as a custom element?
- 32.When does a universal
loadin+page.jsrun? - 33.What must data returned from a server
loadbe? - 34.Why use the
fetchpassed toloadinstead of the global one? - 35.How does a page
loadget data from its layout'sload? - 36.How do you validate a form in a SvelteKit action and return errors?
- 37.How do you call a named action from a form?
- 38.What does
use:enhanceadd to a form? - 39.What is
handleinhooks.server.jsused for? - 40.How do you redirect from a server
loador action? - 41.What do the page options
ssr = falseandcsr = falsedo? - 42.What does a route group like
src/routes/(marketing)/aboutdo? - 43.What does
data-sveltekit-preload-data="hover"do? - 44.How do you make a module server-only in SvelteKit?
- 45.What are
beforeNavigateandafterNavigateused for? - 46.What does
export const snapshotin+page.svelteallow? - 47.How do you build a fully static site with SvelteKit?
- 48.What does this code show after clicking the button?
- 49.Why isn't
countreactive in the importing component? - 50.How do you show a loading indicator during SvelteKit navigation?
- 51.What is
MediaQueryfromsvelte/reactivity? - 52.How can a component expose methods to its parent?
- 53.What does
<script module>do? - 54.Which statement about
{#each}with destructuring is correct? - 55.What is the purpose of
+page.server.jsreturning a promise for slow data? - 56.What is wrong with this
$effect? - 57.What does a
+error.sveltepage show? - 58.What does
$props.id()(Svelte 5.20+) generate? - 59.How do you give a
$bindableprop a fallback value? - 60.How do you render fallback content when no
childrensnippet was passed? - 61.How do you listen to
visibilitychangeondocumentin a component? - 62.How do you pass parameters to a transition?
- 63.How does
in:/out:differ fromtransition:? - 64.Can
<select bind:value>hold objects, not just strings? - 65.How do you read a store's current value once, outside a component?
- 66.What does the second argument of
readabledo? - 67.How do you check whether a context exists before reading it?
- 68.What happens when
export const ssr = falseis set in a+layout.js? - 69.How do you set cache headers for a page from
load? - 70.How do you read and set cookies on the server in SvelteKit?
- 71.What does a param matcher like
[id=integer]do? - 72.What is the
restparameter[...path]useful for? - 73.What happens if both
+page.jsand+page.server.jsexportload? - 74.How do you test a component that expects snippet props?
- 75.What does
untrackNOT do?