How to access the global window variable if there's a local window variable?

Viewed 346

Just out of curiosity, how would you access the global window object inside a function with this signature:

function bla(window){
   // How to access the global 'window' object here? Because 'window' is now local.
}
1 Answers

You could use globalThis

a = 1;

function x(window) {
  console.log(window.a)
  console.log(globalThis.a)
}

x({ a: 2 })

Related