Basic Svelte
Introduction
Bindings
Advanced Svelte
Advanced reactivity
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion
We can easily specify default values for props in Nested.svelte
:
Nested
<script>
let { answer = 'a mystery' } = $props();
</script>
<script lang="ts">
let { answer = 'a mystery' } = $props();
</script>
If we now add a second component without an answer
prop, it will fall back to the default:
App
<Nested answer={42}/>
<Nested />
previous next
1
2
3
4
5
6
<script>
import Nested from './Nested.svelte';
</script>
<Nested answer={42} />