Responding to Clicks
An event is a moment the browser tells you about: a click, a key press, a box being typed into. element.addEventListener("click", handler) says: when this happens to this element, run this function. The function is called a handler, and it runs every time the event happens, as often as it happens.
✦ Hand over the function, don't call it
addEventListener("click", addOne()) runs addOne once, immediately, and hands over whatever it returned, which is undefined, so clicks then do nothing. Without the parentheses you hand over the function itself, to be run later, on each click.
Every handler receives an event object describing what happened. event.target is the element the event happened to, which matters when one handler serves several buttons.
Mark this lesson complete
Signed in, your progress follows you to every device.