Example 1 — Read event.type
Click a button and log the type name.
const btn = document.getElementById("btn");
btn.addEventListener("click", (event) => {
console.log(event.type); // "click"
}); How It Works
- Register a listener. The first argument
"click"is the type name. - User clicks. The browser creates a click event and calls your handler.
- Read
event.type. It returns the string"click". - Match listen name. The value matches what you passed to
addEventListener.

