JavaScript: The Keyword ‘This’ for Beginners
Brandon Morelli
78620

JavaScript also has some interesting behavior with event listeners. Here are some experiments to try:

Create an event listener in the global context to be fired when a button element is clicked. What will ‘this’ be?

Create an event listener in a object constructor to be fired when a button element is clicked and assign the event to a handler in the object. What will ‘this’ be?

Finally do the same thing as above, but make sure the event listener is called handleEvent. What will ‘this’ be?

Was it what you expected?

Understanding the behavior in each instance can help you develop better web applications.