What exactly happens when I create addEventListener ?
The version is very simplified and may differ from how it is made in the browser!
Each DOM element has a list of events. List of events o is an object whose properties are - ("event name": [events]).
Part of the events, these are standard element events.
Example: hover for a link, the link changes color.
Sample event list:
{ "prop1": 1, "prop2": 2, "events": { "onClick": [ function (eventObject) {...}, function (eventObject) {...}, function (eventObject) {...} ... ] "onChange": [ function (eventObject) {...}, function (eventObject) {...}, function (eventObject) {...} ... ] } }
After the user action, a specific event is triggered for this object, for example, onChange :
obj.trigger("onChange", eventObject);
eventObject object containing information about the event (Maybe anything).
After that, all functions of the onChange list are onChange parallelly or sequentially (depending on the execution here). The chain of events can be interrupted
eventObject.preventDefault();
Approximately so.
If I create a lot of handlers does this affect the performance?
It affects. More events, longer to perform. But not much, I think browser manufacturers have optimized this for a long time.