Recall & Review
beginner
Why does directly modifying an array element like
arr[0] = 5 not trigger reactivity in Svelte?Svelte's reactivity tracks assignments to variables, not mutations inside arrays or objects. Changing
arr[0] does not reassign arr, so Svelte does not detect the change automatically.Click to reveal answer
beginner
How can you make Svelte react to changes inside an array after modifying an element?
After changing an element, reassign the array to itself like
arr = arr. This tells Svelte the variable changed and triggers updates.Click to reveal answer
intermediate
What is a common gotcha when updating properties inside an object in Svelte?
Modifying a property like
obj.prop = value does not trigger reactivity because the object reference stays the same. You must reassign the object, e.g., obj = {...obj}, to notify Svelte.Click to reveal answer
intermediate
Why is using methods like
push() or splice() on arrays tricky in Svelte reactivity?These methods mutate the array in place without changing its reference. Svelte won't detect changes unless you reassign the array after mutation.
Click to reveal answer
advanced
What is the recommended pattern to update nested objects reactively in Svelte?
Create a new object with updated nested properties using spread syntax, then reassign the main object. For example,
obj = {...obj, nested: {...obj.nested, key: value}}.Click to reveal answer
In Svelte, which action will trigger reactivity after changing an array element?
✗ Incorrect
Svelte only tracks assignments to variables. Changing an element alone does not trigger reactivity, but reassigning the array variable does.
Which method does NOT trigger Svelte reactivity by itself when used on an array?
✗ Incorrect
arr.push() mutates the array in place without changing its reference, so Svelte won't detect the change unless you reassign the array.
How do you trigger reactivity after changing a property inside an object in Svelte?
✗ Incorrect
Svelte tracks variable assignments, so you must reassign the object to a new copy to trigger reactivity.
What happens if you mutate a nested object property without reassigning the parent object in Svelte?
✗ Incorrect
Svelte does not detect mutations inside nested objects unless the parent object is reassigned.
Which is the best way to update a nested object property reactively in Svelte?
✗ Incorrect
Creating a new object with updated nested properties and reassigning triggers Svelte's reactivity.
Explain why directly modifying an array or object property does not trigger reactivity in Svelte and how to fix it.
Think about how Svelte knows a variable changed.
You got /4 concepts.
Describe the recommended pattern to update nested object properties reactively in Svelte.
Focus on creating new objects instead of changing existing ones.
You got /4 concepts.