Consider a Svelte component that receives a prop. What will happen if the child component tries to change that prop's value?
<script> export let count; </script> <button on:click={() => count = count + 1}>Increment</button> <p>{count}</p>
Think about how Svelte treats props inside child components.
In Svelte, props are readonly inside the child component. Trying to assign a new value to a prop inside the child causes a runtime error because props are immutable from the child's perspective.
Given a parent component passing a prop to a child, what will the child display if the parent updates the prop value?
<!-- Parent.svelte --> <script> import Child from './Child.svelte'; let message = 'Hello'; function update() { message = 'Hi'; } </script> <button on:click={update}>Update Message</button> <Child text={message} /> <!-- Child.svelte --> <script> export let text; </script> <p>{text}</p>
Consider how data flows from parent to child in Svelte.
Props are readonly inside the child, but the parent can update the value it passes. The child will reactively update its display when the parent changes the prop.
Choose the code snippet that enforces the child component cannot modify the prop value.
Think about how Svelte treats props by default.
Svelte props are readonly by default inside the child. No special code is needed to prevent reassignment; attempting to assign to a prop causes a runtime error.
Examine the child component code below. Why does it throw an error when the button is clicked?
<script> export let score; function increase() { score += 1; } </script> <button on:click={increase}>Increase</button> <p>{score}</p>
Recall how Svelte treats props inside child components.
Props in Svelte are readonly inside the child. Trying to reassign 'score' inside the child causes a runtime error.
Since props are readonly inside a Svelte child component, how can the child notify the parent to update a prop value?
Think about how components communicate in Svelte without direct prop mutation.
In Svelte, children cannot modify props directly. Instead, they dispatch custom events to inform the parent, which can then update the prop value.