A. dispatch cannot send events without a second argument
B. dispatch should be imported from 'svelte/internal'
C. dispatch must be called inside a function
D. Missing parentheses when calling createEventDispatcher
Solution
Step 1: Check createEventDispatcher usage
The code assigns dispatch to createEventDispatcher without calling it, missing parentheses.
Step 2: Understand consequences
Without calling createEventDispatcher(), dispatch is not a function, so dispatch('click') causes an error.
Final Answer:
Missing parentheses when calling createEventDispatcher -> Option D
Quick Check:
createEventDispatcher() must be called [OK]
Hint: Always call createEventDispatcher() with () [OK]
Common Mistakes:
Forgetting parentheses after createEventDispatcher
Importing from wrong module
Thinking second argument is mandatory
5. You want a child Svelte component to send two different events, save and cancel, each with different data. Which is the best way to implement this using createEventDispatcher?
hard
A. Create two dispatchers by calling createEventDispatcher() twice, one for each event
B. Create one dispatcher and call dispatch('save', data) or dispatch('cancel', data) as needed
C. Use dispatch('save_cancel', {saveData, cancelData}) to send both events at once
D. Send events by calling dispatchEvent directly on the DOM element
Solution
Step 1: Understand dispatcher usage
One dispatcher handles all custom events; you specify event names when calling dispatch.
Step 2: Evaluate options
Calling dispatch with different event names ('save' or 'cancel') is the correct pattern.
Final Answer:
Create one dispatcher and call dispatch('save', data) or dispatch('cancel', data) as needed -> Option B
Quick Check:
Single dispatcher handles multiple events [OK]
Hint: One dispatcher can send many event types by name [OK]
Common Mistakes:
Creating multiple dispatchers unnecessarily
Sending combined event instead of separate
Using DOM dispatchEvent instead of Svelte dispatch
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.