The addEventListener() method is the modern and preferred
way to handle events in JavaScript. It allows you to attach an event handler to an element
without overwriting existing event handlers.
element.addEventListener(event, function, useCapture);
The addEventListener() method has three major advantages over traditional
methods:
removeEventListener() method.To pass parameters to the function, you must use an anonymous function or an arrow function that calls your function with the arguments.
element.addEventListener("click", function() {
myFunction(p1, p2);
});
There are two ways of event propagation in the HTML DOM:
useCapture parameter out,
it defaults to false (bubbling).
addEventListener() is the industry standard for event
handlingremoveEventListener() to clean up memory and stop
listeners