Junior JavaScript

What is an event listener?

An event listener waits for user actions (like clicks or keypresses) and runs a

function when the event occurs.

Example:

button.addEventListener("click", () => alert("Clicked!"));

More from JavaScript Tutorial

All questions for this course