Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda