Skip to content

removeEventListenerExpressions

Disallow inline function expressions in removeEventListener calls.

✅ This rule is included in the browser logical preset.

The removeEventListener method requires the exact same function reference that was passed to addEventListener in order to successfully remove the event listener. Passing an inline arrow function or function expression to removeEventListener creates a new function instance each time, which means the listener will never be removed because it doesn’t match the original reference.

This is a common mistake that leads to memory leaks and unexpected behavior, as event listeners remain attached to elements even after attempts to remove them.

element.removeEventListener("click", () => {
console.log("clicked");
});
element.removeEventListener("click", function () {
console.log("clicked");
});
window.removeEventListener("resize", () => handleResize());

This rule is not configurable.

This rule should generally always be enabled, as inline function expressions in removeEventListener calls are always ineffective and represent programming errors.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.