Consider a Svelte component that accepts a prop with a default value (an optional parameter). What will be rendered if the prop is not passed?
<script> export let name = "Guest"; </script> <h1>Hello, {name}!</h1>
Think about what default values do when no prop is passed.
When a prop has a default value, Svelte uses that value if the prop is not provided. Here, name defaults to "Guest".
Choose the correct way to define an optional prop count with a default value of 10 in Svelte.
Remember how Svelte exports props with default values.
In Svelte, export let count = 10; declares a prop count with a default value of 10.
Given this Svelte component, what will be displayed after clicking the button twice?
<script> export let start = 5; let count = start; function increment() { count += 1; } </script> <p>Count: {count}</p> <button on:click={increment}>Add</button>
Count starts at start and increments by 1 each click.
Initial count is 5. Clicking twice adds 2, so count becomes 7.
Identify the reason why the default value for title is ignored and undefined is shown.
<script> export let title; if (!title) { title = "Default Title"; } </script> <h2>{title}</h2>
Think about how Svelte handles exported props and reactivity.
Reassigning an exported prop inside the script does not update the reactive value. The correct way is to assign a default value when exporting.
If a parent component passes undefined explicitly to an optional prop with a default value, what will the child component receive?
Consider how JavaScript treats explicit undefined versus missing props.
If a parent passes undefined explicitly, the child receives undefined and does not use the default value. Defaults apply only when the prop is missing.