JavaScript Event Constructor

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Web API constructor

What You’ll Learn

The Event() constructor builds a synthetic Event you can inspect or send with dispatchEvent(). Learn type, bubbles, cancelable, composed, isTrusted, and how it compares to MouseEvent / CustomEvent—with five examples and try-it labs.

01

Create

new Event()

02

Type

Event name string

03

Options

bubbles / cancelable

04

Shadow

composed

05

Fire

dispatchEvent()

06

Status

Baseline widely

Introduction

Browsers create many events for you (clicks, scrolls, loads). Sometimes your script needs to create one too—for tests, custom app signals, or triggering the same listeners without a real user gesture.

new Event("look", options) returns that object. MDN calls it a synthetic event (script-made), as opposed to a browser-fired event. Pair it with target.dispatchEvent(event) to run handlers.

💡
Beginner tip

Creating an event does not fire it. You must call dispatchEvent (or an API that dispatches for you). Synthetic events have isTrusted === false.

Understanding the Event() Constructor

Pass an event type string and an optional options object. The constructor returns a new Event instance ready to inspect or dispatch.

  • type — the event name (for example "look" or "change").
  • bubbles — whether the event bubbles up the tree (default false).
  • cancelable — whether preventDefault() can cancel it (default false).
  • composed — whether it can cross shadow DOM boundaries (default false).
  • Workers — available in Web Workers as well as window contexts.

📝 Syntax

JavaScript
new Event(type)
new Event(type, options)

Parameters

  • type — A string with the name of the event.
  • options (optional) — An object with the fields below.

Option fields (MDN)

OptionDefaultMeaning
bubblesfalseWhether the event bubbles
cancelablefalseWhether the event can be cancelled
composedfalseWhether it triggers listeners outside a shadow root

Return value

A new Event object.

⚡ Quick Reference

GoalCode
Create a simple eventnew Event("look")
Bubbling, not cancelablenew Event("look", { bubbles: true, cancelable: false })
Fire on documentdocument.dispatchEvent(evt)
Fire on an elementmyDiv.dispatchEvent(evt)
Check synthetic?event.isTrusted === false
MDN statusBaseline Widely available (since July 2015)

🔍 At a Glance

Four facts to remember about new Event().

Returns
Event

Synthetic object

Baseline
widely

Since July 2015

Trusted?
false

Script-made

Dispatch
dispatchEvent

To fire handlers

Examples Gallery

Examples follow MDN Event(). Use View Output or Try It Yourself.

📚 Getting Started

Create events and set options.

Example 1 — Create a Basic Event

Minimal constructor call with only a type string.

JavaScript
const evt = new Event("look");

console.log(evt.type);       // "look"
console.log(evt.bubbles);    // false (default)
console.log(evt.cancelable); // false (default)
console.log(evt instanceof Event); // true
Try It Yourself

How It Works

Without options, the event does not bubble and is not cancelable.

Example 2 — Set bubbles, cancelable, composed

Pass an options object to control propagation behavior.

JavaScript
const evt = new Event("look", {
  bubbles: true,
  cancelable: false,
  composed: false
});

console.log(evt.bubbles);    // true
console.log(evt.cancelable); // false
console.log(evt.composed);   // false
Try It Yourself

How It Works

MDN’s classic look example uses bubbles: true and cancelable: false.

📈 Dispatch, Trust & Compare

Fire synthetic events and choose the right constructor.

Example 3 — Create and Dispatch (MDN)

Build a bubbling look event and dispatch it on an element.

JavaScript
const myDiv = document.getElementById("myDiv");
const out = document.getElementById("out");

myDiv.addEventListener("look", () => {
  out.textContent = "look event received!";
});

// create a look event that bubbles up and cannot be canceled
const evt = new Event("look", { bubbles: true, cancelable: false });

// event can be dispatched from any element, not only the document
myDiv.dispatchEvent(evt);
Try It Yourself

How It Works

You can also call document.dispatchEvent(evt). Listeners must match the type string exactly.

Example 4 — isTrusted on Synthetic Events

Script-made events are not trusted; real user clicks are.

JavaScript
const btn = document.getElementById("btn");
const out = document.getElementById("out");

btn.addEventListener("click", (event) => {
  out.textContent = "isTrusted=" + event.isTrusted;
});

// Synthetic click from script:
btn.dispatchEvent(new Event("click", { bubbles: true }));
// → isTrusted=false

// A real user click on the button would log isTrusted=true
Try It Yourself

How It Works

Use isTrusted when security-sensitive actions should only run for real user input.

Example 5 — Event vs CustomEvent

Pick CustomEvent when you need a detail payload.

JavaScript
const target = new EventTarget();

target.addEventListener("ping", (e) => {
  console.log("Event ping", e.type);
});

target.addEventListener("score", (e) => {
  console.log("score detail=", e.detail);
});

target.dispatchEvent(new Event("ping"));
target.dispatchEvent(new CustomEvent("score", { detail: 42 }));
Try It Yourself

How It Works

Event is enough for a bare signal. CustomEvent adds detail without inventing your own properties.

🚀 Common Use Cases

  • Unit / integration tests that fire named events without a real user.
  • App-level signals on an EventTarget (for example "ready", "sync").
  • Triggering the same DOM listeners from a custom toolbar button.
  • Teaching demos that show bubbling with a controlled event.
  • Worker messaging patterns that use the DOM Event model where available.

🔧 How It Works

1

Choose a type

Pass a string name such as "look" or "change".

Type
2

Set options

Optionally set bubbles, cancelable, and composed.

Options
3

Get an Event

A synthetic Event with isTrusted === false.

Object
4

Optional: dispatch

Call target.dispatchEvent(event) to run listeners.

📝 Notes

Universal Browser Support

The Event() constructor is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. It is also available in Web Workers.

Baseline · Widely available

Event() constructor

Safe API for building synthetic Event objects and dispatching them in apps, tests, and demos.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in modern IE versions
Full support
Event() Excellent

Bottom line: Create Event objects with type + options; dispatch with EventTarget.dispatchEvent. Use CustomEvent or MouseEvent when you need more fields.

Conclusion

new Event(type, options) builds a synthetic event with the bubbling and cancelability you choose. Dispatch it to exercise listeners, and use CustomEvent or MouseEvent when you need richer data.

Continue with bubbles, MouseEvent(), dispatchEvent(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Set bubbles when ancestors must hear the event
  • Call dispatchEvent after creating the event
  • Use matching type strings on listeners and constructors
  • Prefer CustomEvent for payloads via detail
  • Check isTrusted for security-sensitive flows

❌ Don’t

  • Expect new Event() alone to run listeners
  • Invent ad-hoc properties when CustomEvent.detail fits
  • Assume synthetic events unlock restricted browser APIs
  • Misspell type names ("Look""look")
  • Skip MouseEvent when you need click coordinates

Key Takeaways

Knowledge Unlocked

Five things to remember about Event()

Build synthetic events, then dispatch when needed.

5
Core concepts
🔁02

bubbles

default false

Options
🔒03

isTrusted

false if synthetic

Security
🔔04

dispatchEvent

fires handlers

Use
🎯05

Baseline

since Jul 2015

Status

❓ Frequently Asked Questions

new Event(type, options) creates an Event object. Events built this way are called synthetic events. You can inspect them or send them with target.dispatchEvent(event).
No. MDN marks the Event() constructor as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is also available in Web Workers.
An optional options object may include bubbles (default false), cancelable (default false), and composed (default false). composed controls whether the event can cross shadow DOM boundaries.
Create it with new Event("my-event", { bubbles: true }), then call element.dispatchEvent(event) or document.dispatchEvent(event). Listeners registered for that type will run.
Browser-generated events have isTrusted === true. Events you create with new Event() have isTrusted === false. Handlers can use that to tell real user input from script-made events.
Use CustomEvent when you need a detail payload. Use MouseEvent (or other UIEvent subclasses) when you need mouse coordinates, buttons, or similar fields. Use Event for a simple named signal with no extra data.
Did you know?

MDN’s classic demo creates a custom "look" event—any string name works. You are not limited to built-in names like click or load.

Next: bubbles

Learn the read-only flag for DOM event bubbling.

bubbles →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful