What Are Events?

Grade 12, page 1 of 9. A one-minute read.

Think about a doorbell.

You don't stand at your front door all day, staring at it, waiting for someone to arrive. That would be exhausting. (And a little creepy.) Instead, you install a doorbell and go about your day. When someone presses the button, the doorbell rings, and then you go and open the door.

Web pages work the same way. Your JavaScript doesn't sit there constantly checking "has the user clicked yet? How about now? Now?" Instead, you tell the browser: "When this button is clicked, run this function." Then your code relaxes, and the browser does the waiting. The moment the click happens, the browser rings the doorbell and runs your function.

That "something happened" moment is called an event. Clicking, typing a key, moving the mouse, submitting a form, scrolling, the page finishing loading: all events. And code that's organized around responding to events is called event-driven programming. It's how basically every interactive app works, from websites to phone apps to video games.

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning