JavaScript Interview Question #59

What is an event in JavaScript?

DOM, Events & Event Loop Fundamentals Mid-Level Intermediate

Quick Interview Answer

An event is a notification that something occurred in the browser or application environment. Examples include click, input, change, submit, keydown, focus, and load.

Detailed Explanation

An event is a notification that something occurred in the browser or application environment. Examples include click, input, change, submit, keydown, focus, and load.

JavaScript can register event listeners and execute callbacks when those events occur. Event-driven programming is central to browser applications because user interfaces respond to actions rather than executing only as a fixed sequence.

Code Example

const button = document.querySelector("#save");

button.addEventListener("click", event => {
    console.log("Save clicked", event.type);
});