What are events?
Suppose you click a button on a webpage, type in some letters in a text box, perform swiping gestures across the screen, or just simply scroll across the webpage; you're essentially performing certain actions on the webpage.
As we've seen before, the action can be clicking a button, typing text, swiping or even scrolling around, and way more than this. The action can either be a physical action carried out by the user, or an internal action carried out by the browser itself, like the completion of a resource's loading.
To get even simpler, an event is just something happening within the webpage - something that can be responded to, for instance showing an alert box on the click of a button.
As you might realise, the list of all such possible actions that can happen on a webpage is exhaustive - and so are events.
To get a realisation of this fact, consider doing a very simple exercise - just name 10 different actions you think can happen on a webpage and note them down on a piece of paper. See if you are able to only end at 10 - you'll more than likely go running past this limit!
Now before we move on to explore it, we have to first unravel the question: why we even need events?
Why we need events?
This is the idea on which events operate: monitor an action and then execute some code once it happens. Truly, an extremely simple and natural idea!
Events emulate a webpage as being an interactive object - with whom a user can communicate with, at his/her actions. Just carry out some actions and then see the webpage respond to them.
Without events a webpage is just a static display of HTML, nothing more than that. Imagine visiting a webpage with no event at all - you can't interact with literally anything, it's just the content to be read. There's no interactivity, no user experience, and at the end of the day no excitement about the website.
In the coming chapters, we'll start by discovering the various ways to assign event handlers to HTML elements, using event properties and listeners; before diving into some more involved topics such as event objects and event propagations. After covering all this, we'll finally head over to consider some real events in action, and see the numerous applications where there used.
To say it in one sentence: it's a unit of joy!