0
0
Svelteframework~20 mins

Layout load functions in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Layout Load Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this layout load function return?
Consider this SvelteKit layout load function. What will be the value of data available to the layout component?
Svelte
export async function load() {
  return {
    user: { name: 'Alice', role: 'admin' },
    settings: { theme: 'dark' }
  };
}
A{ user: { name: 'Alice' }, settings: { theme: 'dark' } }
B{ user: { role: 'admin' }, settings: { theme: 'light' } }
C{ user: { name: 'Alice', role: 'admin' }, settings: { theme: 'dark' } }
Dundefined
Attempts:
2 left
💡 Hint
The load function returns an object that becomes the data prop in the layout.
state_output
intermediate
1:30remaining
How many keys are in the data object from this layout load?
Given this layout load function, how many top-level keys will data have in the layout component?
Svelte
export function load() {
  return {
    user: { id: 1 },
    notifications: [],
    preferences: { lang: 'en' }
  };
}
A3
B2
C1
D0
Attempts:
2 left
💡 Hint
Count the keys returned in the object.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in a layout load function?
Identify the option that will cause a syntax error when used as a layout load function in SvelteKit.
A} ;} 'boB' :resu { nruter { )(daol noitcnuf cnysa tropxe
Bexport function load() { return { user: 'Bob' } }
Cexport async function load() { return { user: 'Bob' }; }
Dexport function load() { return user: 'Bob' }
Attempts:
2 left
💡 Hint
Check the syntax of the return statement object.
🔧 Debug
advanced
2:00remaining
Why does this layout load function cause a runtime error?
Examine this layout load function. Why will it cause a runtime error when the layout tries to access data.user.name?
Svelte
export function load() {
  return {
    user: null
  };
}
ABecause the load function must be async.
BBecause <code>user</code> is null, accessing <code>name</code> causes a TypeError.
CBecause the return object is missing a <code>name</code> key.
DBecause the load function does not return a Promise.
Attempts:
2 left
💡 Hint
Think about what happens if you try to access a property on null.
🧠 Conceptual
expert
2:30remaining
What happens if a layout load function returns a Promise that rejects?
In SvelteKit, if a layout load function returns a Promise that rejects with an error, what is the expected behavior?
AThe error is caught by SvelteKit and the error page is shown.
BThe app crashes and stops loading any pages.
CThe layout silently ignores the error and renders with empty data.
DThe load function retries automatically until it succeeds.
Attempts:
2 left
💡 Hint
Think about how frameworks handle rejected Promises in load functions.