Challenge - 5 Problems
Layout Load Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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' } }; }
Attempts:
2 left
💡 Hint
The load function returns an object that becomes the
data prop in the layout.✗ Incorrect
The load function returns an object with
user and settings keys. This object is passed as data to the layout component.❓ state_output
intermediate1: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' } }; }
Attempts:
2 left
💡 Hint
Count the keys returned in the object.
✗ Incorrect
The returned object has three keys: user, notifications, and preferences.
📝 Syntax
advanced2: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.
Attempts:
2 left
💡 Hint
Check the syntax of the return statement object.
✗ Incorrect
Option D is missing curly braces around the returned object, causing a syntax error.
🔧 Debug
advanced2: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 }; }
Attempts:
2 left
💡 Hint
Think about what happens if you try to access a property on null.
✗ Incorrect
Accessing
data.user.name when user is null causes a TypeError because null has no properties.🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about how frameworks handle rejected Promises in load functions.
✗ Incorrect
SvelteKit catches errors from rejected Promises in load functions and shows the error page to inform the user.