Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda