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

154
Vistas
Why is the 'this' value different in Javascript?
var obj = {
    a: 2,
}
var a = 3;

const func = () => {
    console.log(this.a);
}

function test() {
    setTimeout(func, 100);
}

function test2() {
    setTimeout(() => {
        console.log(this.a);
    }, 100);
}
test.call(obj); //3
test2.call(obj); //2

It seemed that the test and test2 are the same, but the returned result is different, what's the problem with 'this'?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

with test arrow function, this will refer to the window object, and as var a = 3, the a will be assigned as a property to the window, it will be like

window.a

But in test2 this will refer to the obj object.

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