Back to the 2023 paper

Module III: Basics of Web Programming

20237m

Write a short note on Event-driven Programming.

Worked SolutionAI Assisted

Event-driven Programming

Event-driven programming is a programming model in which program execution is controlled by events such as mouse clicks, keyboard input, network messages, timers or other system actions.

Main components

  1. Event source: The object that generates an event, e.g. a button.
  2. Event: Represents an occurrence, e.g. a click.
  3. Event handler/listener: Code that responds to the event.
  4. Event loop/dispatcher: Detects events and dispatches them to appropriate handlers.

Example

button.addEventListener("click", function () {
    alert("Button clicked");
});

Here the button is the source, click is the event, and the function is the handler.

Advantages

  • Natural for interactive applications.
  • Separates event detection from response logic.
  • Useful for GUIs and web applications.

Conclusion: Instead of executing everything in one fixed sequence, an event-driven program waits for events and responds to them.

Similar questions