DEV Community

Cover image for Life without .addEventListener()
slj2222
slj2222

Posted on • Edited on

Life without .addEventListener()

Can you imagine your life without .addEventListener()... probably not. Software Engineers/Developers know exactly what I'm talking about, but the general public has no idea how their lives would be effected if there were no event listeners.

For those of you who are reading this and thinking to yourself, "what the heck is an event listener"? An event listener is "An event listener is a procedure in JavaScript that waits for an event to occur. The simple example of an event is a user clicking the mouse or pressing a key on the keyboard...an inbuilt function in JavaScript which takes the event to listen for, and a second argument to be called whenever the described event gets fired." -according to GeeksforGeeks.

If you're still reading this and still thinking to yourself, "what the heck", let me further explain. Think about your most visited websites, apps on your phone, or you preferred social media platform (this list might be long). On your list, every one of the websites or apps is interactive, meaning there are places on the page that you can click on, either in the form of liking your friends photo, or something as boring as logging in to pay a bill. These features of your favorite websites/apps wouldn't be possible without event listeners.

Event listeners are written in the code to make your experience the best it can be when visiting the webpage/app. They sit silent in the background waiting for you to commit the certain action on your screen that will trigger their attached set of instructions. For instance, once you double-click that photo of your friends cute little puppy on Instagram, everyone knows you liked the photo. This is because the "feature", we'll call it, was sitting in the code not doing anything until you double-clicked the photo. Once you double-clicked the photo, the event listener (listening for the "double-click") fired off and executed a set of instructions. That set of instructions is a topic for another day.

There are so many different "features" that are built into websites/apps that we all interact with on a daily basis. Like I said before, they are there to enhance our experiences while on the web, and they stem from even listeners.

The important thing is, imaging your life without an event listener waiting for you to double-click your friend's photo. If that is hard to imagine, imagine a website/app that you couldn't click on. How boring would that be? In my opinion, life would be MUCH different, without event listeners but again, that is a topic for another day.

Top comments (0)