Default prop values in Svelte
📖 Scenario: You are building a simple Svelte component to display a user's profile card. Sometimes the user might not provide all the information, so you want to set default values for some props.
🎯 Goal: Create a Svelte component called UserProfile.svelte that accepts props for name, age, and location. Set default values for age and location so the component still shows meaningful info if those props are not passed.
📋 What You'll Learn
Create a
name prop without a default valueCreate
age and location props with default valuesRender the props inside the component
Use Svelte syntax for default prop values
💡 Why This Matters
🌍 Real World
Setting default prop values is common in UI components to ensure they display useful information even when some data is missing.
💼 Career
Knowing how to handle default props is essential for frontend developers working with Svelte or similar frameworks to build robust, reusable components.
Progress0 / 4 steps