Question · JavaScript and TypeScript course · Module 8: Events and the DOM
Creating Custom Events
How do you create a custom event with additional data in JavaScript?
Answer options
- new Event('name', { data: { key: 'value' } })
- new CustomEvent('name', { detail: { key: 'value' } })
- document.createEvent('name', { detail: { key: 'value' } })
- new CustomEvent('name', { body: { key: 'value' } })
You can check the correct answer by solving this task in the CodeWorlds game.