JavaScript Interview Question #61

What is the event object?

DOM, Events & Event Loop Fundamentals Mid-Level Intermediate

Quick Interview Answer

When an event listener runs, the browser passes an event object containing information about the event. Common properties include type, target, currentTarget, and methods such as preventDefault and stopPropagation.

Detailed Explanation

When an event listener runs, the browser passes an event object containing information about the event. Common properties include type, target, currentTarget, and methods such as preventDefault and stopPropagation.

Specialized events add more information. KeyboardEvent exposes key-related data, while MouseEvent includes pointer coordinates and mouse-button information.

Code Example

document.addEventListener("click", event => {
    console.log(event.type);
    console.log(event.target);
    console.log(event.currentTarget);
});