The on* properties, like onclick, were always a bit of a blunt instrument, overwriting any previous handler. addEventListener allows for multiple handlers, which is essential for modular design.
Why:
The standard and modern way to attach an event listener to a DOM element in JavaScript is using addEventListener(). It allows multiple listeners for the same event type on a single element. Options 1 and 3 are non-standard methods, and Option 4 (attachEvent) is an older, Internet Explorer-specific method.
addEventListener() is the standard way to register a click handler on a DOM element. on() is commonly used by libraries like jQuery, while attachEvent() is an old Internet Explorer method. setEventHandler() is not a standard DOM method.
Nice one, @Apexcodes — the way you sorted the distractors was the best part. Calling out on() as the jQuery one and attachEvent as the old IE thing, plus flagging setEventHandler as not standard at all, made it way clearer than just picking the right answer. That’s exactly the bit that trips people up on these easy ones.