Recall & Review
beginner
What does
export let do in a Svelte component?It declares a property (prop) that the component can receive from its parent. This lets the parent pass data into the child component.
Click to reveal answer
beginner
How do you set a default value for a prop in Svelte?
You assign a value when declaring the prop, like <code>export let name = 'Guest';</code>. If the parent doesn't pass a value, the default is used.Click to reveal answer
intermediate
Can you change the value of a prop inside a Svelte component after it is set?
Yes, you can reassign the prop inside the component, but it won't affect the parent. Props are one-way: parent to child.
Click to reveal answer
beginner
Why use
export let instead of just let in Svelte?export let makes the variable a prop that the parent can set. Plain let is private to the component and can't receive values from outside.Click to reveal answer
intermediate
What happens if a parent component does not pass a prop declared with
export let and no default is set?The prop will be
undefined inside the child component, which might cause errors if not handled.Click to reveal answer
In Svelte, how do you declare a prop named
title?✗ Incorrect
The correct syntax to declare a prop is
export let title;.What is the default value of a prop if you write
export let count = 10; and the parent does not pass count?✗ Incorrect
The default value 10 is used if the parent does not provide a value.
If a parent passes a prop to a child component, can the child update the parent's value directly?
✗ Incorrect
Props flow one-way from parent to child. The child cannot directly change the parent's value.
What happens if you declare
let name; without export in a Svelte component?✗ Incorrect
Without
export, the variable is private and cannot receive values from the parent.How can you provide a fallback value for a prop in Svelte?
✗ Incorrect
Assigning a value during declaration with
export let sets a default fallback.Explain how to declare and use props in a Svelte component using
export let.Think about how a parent sends data to a child component.
You got /4 concepts.
Describe what happens if a prop declared with
export let is not passed by the parent and no default value is set.Consider what the child component sees when no value is given.
You got /3 concepts.