EMZETT.
Login

Events

In short: An event is an occurrence the program reacts to: a click, a key, a timer, a message. You register a function (handler) that is then called.

In more detail: Event-driven programming reverses the flow: instead of working step by step, the program waits in a loop for events and dispatches them to handlers. This is the basic principle of user interfaces and web pages.

In detail

button.addEventListener("click", (e) => {
  console.log("Clicked", e.target);
});
  • Source: whoever triggers the event (button, window, network).
  • Handler/listener: function that reacts.
  • Event object: holds details (position, key, target).
  • Bubbling: in the browser an event rises from the target through its parents. stopPropagation() stops it.
  • Types: click, input, submit, keydown, load.
  • Other languages: C# event and delegates (Delegates and events), Java listeners, Python tkinter.bind.
  • Concurrency: managed by the event loop.

See also: Button, Function