Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

311
Vistas
Why can you redefine globalThis and global but not window?

let globalThis = undefined gives me no error in browsers
let [global, globalThis] = [undefined, undefined] gives me no error in node
However let window = undefined throws SyntaxError

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

window must be present for the page(frame) to work. Since window is declared in a global execution context, you can't redeclare it with let or const.

Although, it's possible to call the following code: var window = undefined; or window = undefined;, but it won't do anything to the window object. That's because the setter on the window object is undefined and configurable descriptor is set to false, disallowing changes and deletion of the window property. You can see that if you that with the following code:

console.log(Object.getOwnPropertyDescriptor(this, 'window'))

You are still able to declare your own window variable inside any other lexical context, other than the global one:

const test = () => {
  const window = 123;
  console.log('in test fn:', window);
}
test()
console.log('in global:', window)

But why can I change the globalThis then? You can change it because globalThis is the property of window. And doesn't seem to have an empty setter and configurable descriptor is set to true, allowing changes to this property. All that means, you can do anything you want with globalThis property :)

console.log(window.hasOwnProperty('globalThis'));
console.log(Object.getOwnPropertyDescriptor(window, 'globalThis'));

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda