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

215
Visualizações
how javascript handles variables in objects?

I have a question about declaring a variable in an object. Assuming that global or window is also an object, why is it not possible to declare a variable using let in an object that is a child of the window object? I do not understand that. Thanks for the answer and sorry for the English but I hope you understand the question.

this doesnt worked

let a = 'global';
console.log(a);
const outsideObj = {

    let b = 'outside var',
    logIt() {
        console.log(this);
        console.log(a);
        console.log(this.b)
    }
};

outsideObj.logIt();

this worked

console.log(this);

let a = 'global';
console.log(a);

const outsideObj = {

    b: 'outside var',
    logIt() {
        console.log(this);
        console.log(a);
        console.log(this.b)
    }
};

outsideObj.logIt();

i dont get difference between windows object and regular object why is it possible in parent and not in child?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

An object has properties and can be created by an object literal with property definitions.

A scope has variables and can be created by a block statement with variable declarations.

Do not mix these two concepts, especially not syntactically. That global var and function declarations implicitly create properties on the global object is a special case, and also only works by the global object being provided by the runtime - there is no object literal for it.

about 4 years ago · Santiago Gelvez 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