This is a great article on what might seem like the simple act of removing event listeners from objects in #JavaScript. There are more options than just removeEventListener(). Particularly interesting, is using the AbortController.
https://www.macarthur.me/posts/options-for-removing-event-listeners
Then for more AbortController goodness, check out @samthor's posts: https://whistlr.info/2022/abortcontroller-is-your-friend/ and more recently https://whistlr.info/2023/abortcontroller-for-expiry/.
There's some very cool things you can use the AbortController for!