Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Using parentNode to Traverse Up the DOM

Kevin S
Kevin S
Data Analysis Techdegree Student 15,862 Points

What Exactly is event

Hi All,

Is event just the name of a function? I know that you make an anonymous arrow function in this fashion () => { }. If you put event in there, you are simply giving the function a name so that you can reference it later right? Just trying to clear up my thoughts about this.

Otec Perez Glass
Otec Perez Glass
7,678 Points

Hello Kevin Shields So any time we interact with a website you generate all kinds of events. An Event it is something you do on web-page like moving your mouse over, clicking etc the browsers listen for the event and in JS we can do something in response to an event.

also as an example

document.body.addEventListener('click', (e) =>{
// some code 

where click is a string representing the event type click after that we need to specified the listener, or we can call it listener options so the addEventListener takes an event type and callback a function which this call back function it is also call an Event handler.

e is parameter that is passed by the caller function when the Event is fired so when ever the events fires, this function does something like callback(eventFired).

When the event handler it is call it receive an event object as its first argument is like the anonymous function is saying "Hey when you call me be sure of give me an argument ", so when the click is happens or the event is fired, the browser will call the anonymous function with an argument, which will be the event Object also the object is created at the moment the event occurs as an object it has properties like event.target and other

1 Answer

when any event occurs( in this case the 'click' event), an event object is automatically created. The event object contains relevant data about the event that took place, and we can use the event object passed into the event handler to retrieve this information.This can be confusing to understand and i found this YouTube video to be VERY helpful : https://www.youtube.com/watch?v=C9Ad3420Kmw