Event
In one line
An event is a signal the browser sends when something happens — a click, a key press, a page load, and so on.
In simple words
An event is a notification that something has happened in the browser or in your program. Clicks, key presses, mouse movements, form submissions, page loads, timer expirations, and network responses all generate events.
JavaScript lets you "listen" for events and run code in response. You register an event listener with element.addEventListener('click', handler). When the user clicks that element, the browser calls your handler function with an event object containing details about what happened.
The event object carries useful information: which key was pressed, the mouse coordinates, the target element, and more. You can also stop default behavior (e.preventDefault()) or stop the event from bubbling up the DOM (e.stopPropagation()).
Example
const button = document.querySelector("button");
button.addEventListener("click", (event) => {
console.log("Button clicked!");
console.log("Clicked element:", event.target);
});When the button is clicked, the browser fires a click event and calls the handler with an event object.
Related terms
Related Resources
Related Lessons
- DOM
Events are the bridge between the DOM and JavaScript
Learn the fundamentals
Deepen your understanding with structured lessons on this topic.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.