Event.prototype.defaultPrevented
Returns a boolean indicating whether or not the call to Event.preventDefault() canceled the event
Syntax
event.defaultPreventedReturn Value
A boolean: true if preventDefault() was called, false otherwise
Examples
document.querySelector('form')!.addEventListener('submit', (e) => {
e.preventDefault()
console.log(e.defaultPrevented) // true
})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')
}
}const event = new Event('test', { cancelable: true })
console.log(event.defaultPrevented) // false
event.preventDefault()
console.log(event.defaultPrevented) // trueUnderstanding 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
Event.prototype.preventDefaultTells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be
Event.prototype.stopPropagationPrevents further propagation of the current event in the capturing and bubbling phases
EventTarget.prototype.dispatchEventDispatches an event to this EventTarget, invoking the affected event listeners in the appropriate order
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.