globalThis is the standardized way to reference JavaScript’s global object across environments. Attach a property to it when a value needs to be available globally; prefer it to environment-specific names such as window or global unless using an environment-specific API. section 7.4
Listing 7.7 Attaching a value to the global object
// In globals.mts
declare global { #A
var ninjaName: string; #A
} #A
globalThis.ninjaName = "Naruto"; #B
// In main.mts
import "./globals.mts"; #C
console.log(`It's me, ${ninjaName}!`);
This example attaches ninjaName to globalThis in one module so another module can use the name without importing it. section 7.4
