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

113
Visualizações
Currying or closure

Hello I'm doing a javascript coding interview, to prepare for an upcoming one. i had a question that confused me a bit. The question is as follow :

What concept is being illustrated below ?

function makeAdder(x) {
  return function (y) {
    return x + y;
  };
}

var addFive = makeAdder(5);
console.log(addFive(3));

There were 4 answers to pick from and then there's : Currying and Closure

I thought both of these were right. I ended up picking currying, but i really thought this is illustrating closures as well? Could you explain why this is not illustrating closures?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Currying is always a syntax Sugar for closures.It doesn’t call a function. It just transforms it.

For Your above case It's Just Closures because you are taking another variable which stores inner function and executing differently . Like addFive is inner function which is being invoked later.

If you want to to currying it would be like the below example i have created. Currying is the concept of closure, due to its leading exection braces which help inner function executions at same times. So here you don't have to take another variable to store for calling the inner function.

By definition, currying should convert sum(a, b, c) into sum(a)(b)(c).

function makeAdder(x) {
  return function (y) {
    return x + y;
  };
}


console.log(makeAdder(5)(3));

about 4 years ago · Juan Pablo Isaza Relatório
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