
An event listener waits for something to happen — a click, a keypress, a form submission — and then runs a function. Use element.addEventListener('click', myFunction) to attach one. This is the foundation of all user interactivity in the browser. Always use addEventListener rather than inline HTML event attributes like onclick.
Reference:
TaskLoco™ — The Sticky Note GOAT