Event

Event

Creates a new Event object that can be dispatched to an EventTarget

Syntax

JavaScript
new Event(type, options?)

Parameters

ParameterTypeDescription
typestringThe name of the event
optionsEventInitOptions: bubbles, cancelable, composed

Return Value

A new Event object

Examples

Basic Usage
const event = new Event('change', { bubbles: true })
const input = document.querySelector('input')!
input.dispatchEvent(event)
Practical Example
const clickEvent = new Event('click', {
  bubbles: true,
  cancelable: true
})
document.querySelector('button')?.dispatchEvent(clickEvent)
Advanced Usage
function triggerEvent(el: Element, type: string) {
  el.dispatchEvent(new Event(type, {
    bubbles: true,
    cancelable: false
  }))
}

Understanding Event

The Event method in JavaScript creates a new Event object that can be dispatched to an EventTarget. It belongs to the Event object and is one of the most widely used methods for working with event values in modern JavaScript and TypeScript applications.

The method signature is new Event(type, options?). It accepts 2 parameters: type, options. When called, it returns a new event object. Understanding when and how to use Event() helps you write more expressive, readable code.

Common use cases for Event include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like event-customevent, event-dispatchevent, event-addeventlistener, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Event is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Event Methods

Other methods in the Event object

Related Tools

More Event Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.