JavaScript JavaScript and the DOM Traversing the DOM Using parentNode to Traverse Up the DOM

Kevin S
Kevin S
14,941 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 and other