When the code contained in a script
element is evaluated, the result of that code evaluation becomes part of the runtime environment of the page. Removing the script
element does not remove the resulting structures (functions, etc.) from the environment.
So if the script defines functions, or hooks event handlers to elements, or creates new properties on existing objects (including the global object), those functions, handlers, and properties remain in memory even if the script
that defined them is removed from the DOM (subject to the usual JavaScript garbage collection; e.g., objects not referenced anywhere are eligible for GC, but the script
element has no bearing on that). The script
element is merely a mechanism for conveying the code to the browser.