0
0
Svelteframework~5 mins

Declaring props with export let in Svelte - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aexport let title;
Blet export title;
Cprop title;
Dexport prop title;
What is the default value of a prop if you write export let count = 10; and the parent does not pass count?
A0
Bnull
Cundefined
D10
If a parent passes a prop to a child component, can the child update the parent's value directly?
ANo, props are one-way from parent to child
BOnly if you use a store
COnly if you use <code>export let</code>
DYes, props are two-way bound by default
What happens if you declare let name; without export in a Svelte component?
AIt becomes a prop
BIt is private to the component and cannot receive values from outside
CIt causes an error
DIt is automatically exported
How can you provide a fallback value for a prop in Svelte?
AUse <code>prop: defaultValue;</code>
BUse <code>let prop = defaultValue;</code>
CUse <code>export let prop = defaultValue;</code>
DUse <code>default prop = defaultValue;</code>
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.