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

175
Vistas
returned value undefined but not undefined right before returned. closure related?

Why is the returned value undefined when it looks fine right before it is return when I console log it. I assume it is something to do with closure but don't get it. The code and the console logs for two different test calls are below:

CODE:

function addTogether() {
  const [a, b] = arguments;
  console.log(`a: ${a}  b: ${b}`);

  if (typeof a !== 'number') {
    return undefined;
    }
  if (b !== undefined){
    if (typeof b !== 'number'){
      return undefined;
    } else{
      let sum = a+b;
      console.log("sum being returned =", sum)
      return sum;
      }
  }
return ((b)=>{
  addTogether(a,b);
  })
}

console.log("returnVal =", addTogether(2,5));
console.log("returnVal =", addTogether(5)(7));

CONSOLE OUTPUT:
a: 2  b: 5
sum being returned = 7
returnVal = 7
a: 5  b: undefined
a: 5  b: 7
sum being returned = 12
returnVal = undefined
about 4 years ago · Juan Pablo Isaza
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