Mike
Mike

Reputation: 1

How does event handler "event" parameter work?

I just wrote a piece of code in Javascript where I added an event Listener and then I wrote the event Handler like this:

function checkBoxes() {
   const answer=event.currentTarget;
   ...
   ...
}

I always thought that it was mandatory to write a parameter in order to use the Event object in a handler, but this code still works, and I would like to know why.

Upvotes: 0

Views: 29

Answers (1)

Quentin
Quentin

Reputation: 944454

See MDN:

The read-only Window property event returns the Event which is currently being handled by the site's code. Outside the context of an event handler, the value is always undefined.

Upvotes: 1

Related Questions