Complete the code to define a Svelte component with an optional parameter name that defaults to 'Guest'.
<script>
export let name = [1];
</script>
<p>Hello, {name}!</p>The optional parameter name is given a default value of "Guest" using the assignment syntax. This means if no value is passed, it uses "Guest".
Complete the code to define a Svelte component with an optional number parameter count defaulting to 0.
<script>
export let count = [1];
</script>
<p>Count: {count}</p>The optional parameter count is given a default number value 0. This ensures it is a number, not a string.
Fix the error in the Svelte component by completing the optional parameter color with a default value of 'blue'.
<script> export let color [1] 'blue'; </script> <p style="color: {color}">This text is colored.</p>
In Svelte, to set a default value for a prop, use the equals sign =. The colon or arrow are invalid here.
Fill both blanks to create a Svelte component with optional parameters title defaulting to 'Welcome' and show defaulting to true.
<script> export let title = [1]; export let show = [2]; </script> {#if show} <h1>{title}</h1> {/if}
The title parameter defaults to the string "Welcome" and show defaults to the boolean true. This controls whether the heading shows.
Fill all three blanks to create a Svelte component with optional parameters user defaulting to 'Guest', age defaulting to 18, and active defaulting to false.
<script> export let user = [1]; export let age = [2]; export let active = [3]; </script> <p>{user} is {age} years old.</p> <p>Status: {active ? 'Active' : 'Inactive'}</p>
The user defaults to "Guest" (string), age defaults to 18 (number), and active defaults to false (boolean). This sets clear default states.