The same program taken to the page and to two real Workers: window, self, this and a top-level var answer differently in each room, globalThis the same in…
A library that runs anywhere (a browser, a Worker, Node for SSR, an edge runtime) needs the global object for feature detection, polyfills or configuration. A window || self || global chain looks safe but breaks in the place you did not test; globalThis removes that whole class of "is not defined" errors.
One name for the global object, anywhere
window is not defined in a Worker or Node Outside the page there is no window, and naming it is a ReferenceError. Use globalThis for code that runs anywhere; window only when the code really is page-only.... : this gives undefined in ESM At the top of a module, this is undefined, not the global object: the lookup chain leaks right there. Use globalThis instead.var x at the top of a module does not stick to globalThis.x In a module, var makes no global property (only a classic script does). If you really need a global, write it openly: globalThis.x = ….typeof window in a back room A Worker has no window.this in a module and in a classic script undefined, or the global object.var kasir stick in one room only 'kasir' in globalThis in a classic script and in a module.kasir = 'Bayu' with no declaration A module stops at its first line.