Recall & Review
beginner Click to reveal answer
What is a Svelte action?
A Svelte action is a function that can be applied to an HTML element to add reusable behavior or logic directly to that element.
beginner Click to reveal answer
How do actions help with code reuse in Svelte?
Actions let you write behavior once and apply it to many elements, avoiding repeated code and making your app easier to maintain.intermediate Click to reveal answer
What parameters does a Svelte action receive?
A Svelte action receives the HTML element it is applied to and optionally a parameter to customize its behavior.
intermediate Click to reveal answer
How does Svelte clean up actions when elements are removed?
If an action returns a function, Svelte calls it to clean up resources or event listeners when the element is removed from the DOM.
intermediate Click to reveal answer
Why is using actions better than inline event handlers for reusable behavior?
Actions separate behavior from markup, making code cleaner, easier to reuse, and easier to test compared to inline event handlers.
What does a Svelte action primarily add to an element?
✗ Incorrect
Svelte actions add reusable behavior or logic to elements, not styling or HTML structure.
What argument does a Svelte action receive first?
✗ Incorrect
The first argument to a Svelte action is always the HTML element it is attached to.
How can a Svelte action clean up when an element is removed?
✗ Incorrect
Returning a cleanup function from an action lets Svelte call it when the element is removed.
Why use actions instead of inline event handlers for repeated behavior?
✗ Incorrect
Actions help keep code clean and reusable, unlike inline handlers which duplicate code.
Can Svelte actions accept parameters to customize behavior?
✗ Incorrect
Svelte actions can accept a second argument to customize their behavior.
Explain how Svelte actions help add reusable behavior to elements.
Think about how you can write one function and use it on many elements.
You got /5 concepts.
Describe the lifecycle of a Svelte action from applying to cleanup.
Consider what happens when the element appears and disappears.
You got /5 concepts.
