A doorbell is wired once. After that you go about your day, and whenever someone presses the button it rings; you never stand at the door checking. An event handler is that wiring for a program. In JavaScript, button.addEventListener('click', sayHi) tells the browser: whenever this button is clicked, call the function sayHi. That line runs once, during setup; sayHi runs later, once per click, perhaps zero times, perhaps a hundred.
This changes how you trace a program. Code outside handlers runs top to bottom when the page loads. Code inside a handler runs only when its event happens, so the order depends on the user. If a page has count = 0 and a click handler that runs count = count + 1, then after three clicks count is 3, wherever in the file the handler happens to be written.
Passing a function is not the same as calling it. button.addEventListener('click', sayHi()) has parentheses, so sayHi runs straight away during setup, and what gets attached is its return value, usually undefined; later clicks do nothing. Without the parentheses you hand over the function itself, to be called later. A loop that keeps asking 'has the key been pressed yet?' is also not an event handler; that is polling, and it burns effort that a handler avoids.
Think of it like this. A smoke alarm is an event handler for smoke: installed once, it waits silently and reacts only when smoke arrives, as many times as that happens. You never tell it when to sound; the event does. Unlike an alarm on the ceiling, a handler can be attached twice by mistake, and then one event sets it off twice.
Core idea. Event-driven programming reverses the usual flow — instead of your code deciding when to run, external events trigger it.