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

157
Vistas
Trying to understand difference beetween functions arrow and functions in javascript

I'm trying to understand the difference beetween functions arrow and functions in javascript, with the help of some website, and from what I seemed to understand, it's the this binding that change in the case So I understood that in function arrow, this is binded to the closest non-arrow function parent this and in regular function, this is binded from the closest this

So with that in mind, I was doing some test in the browser console and came up with this:

test = {
    test_name: "OK",
    test_func: function() {
        console.log(this.test_name);
        (() => {
            console.log(this.test_name);
            function b() {
                console.log(this.test_name);
            }
            b();
        })();
    }
}
test.test_func();

I was excepting to get

OK
OK
OK

but what I get is

OK
OK
undefined

And I can't understand why since I get 'OK' in the arrow function, why don't I get 'OK' in the b() function?

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

0

From w3schools:

The handling of this is also different in arrow functions compared to regular functions.

In short, with arrow functions there are no binding of this.

In regular functions the this keyword represented the object that called the function, which could be the window, the document, a button or whatever.

With arrow functions the this keyword always represents the object that defined the arrow function.

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