Event

Event.prototype.defaultPrevented

Returns a boolean indicating whether or not the call to Event.preventDefault() canceled the event

Syntax

JavaScript
event.defaultPrevented

Return Value

A boolean: true if preventDefault() was called, false otherwise

Examples

Basic Usage
document.querySelector('form')!.addEventListener('submit', (e) => {
  e.preventDefault()
  console.log(e.defaultPrevented) // true
})
Practical Example
function safeDispatch(el: HTMLElement, name: string) {
  const event = new Event(name, { cancelable: true })
  el.dispatchEvent(event)
  if (event.defaultPrevented) {
    console.log('Event was cancelled by a handler')
  }
}
Advanced Usage
const event = new Event('test', { cancelable: true })
console.log(event.defaultPrevented) // false
event.preventDefault()
console.log(event.defaultPrevented) // true

Understanding Event.prototype.defaultPrevented

The Event.prototype.defaultPrevented method in JavaScript returns a boolean indicating whether or not the call to Event.preventDefault() canceled the event. 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 event.defaultPrevented. When called, it returns a boolean: true if preventdefault() was called, false otherwise. Understanding when and how to use defaultPrevented() helps you write more expressive, readable code.

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

Browser support for Event.prototype.defaultPrevented 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.