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

216
Vistas
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 Respuestas
Responde la pregunta

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 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