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

95
Vistas
Why this Immediately Invoked Function returns number?

I want to understand why this code returns number:

(function f(f){
    return typeof f();
})(function(){return 1;});

First I assume it will return undefined since function f executes before the last function, but then I run the code with console logs and the result was number. Anyone would mind explaining why this was the output?

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

0

f inside the first function’s body refers to the parameter called f. An equivalent version without the confusing shadowing would be:

(function f(g){
    return typeof g();
})(function(){return 1;});

And an equivalent version with the IIFE separated into a function definition and a call:

function f(g) {
    return typeof g();
}

f(function () {
    return 1;
});

(If it’s not clear why this returns 'number', you should review the concept of functions as values before jumping into intentionally more complicated IIFEs with shadowing that also make use of the concept.)

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