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

278
Visualizações
Javascript - Why does a function work on the last call only?

Just started learning how to code. The first lesson taught how functions are used. For the below add function, whenever I call the function more than once, the output is displayed only for the last one. Does a function have to be written separately for each time I call?

function add(first, second) {
  return first + second;
}

add(1,2);
add(7,9);
add(3,5);

Output: 8

How can I get an output to all three?

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

0

Your add function returns the computation, it does not print anything. So once you call it, all the work will be done and returned, and if you want to see what is returned, all you need is to console them in order to appear in the developer panel

function add(first, second) {
  return first + second;
}

console.log(add(1,2)); // <- HERE
console.log(add(7,9);
console.log(add(3,5));
about 4 years ago · Juan Pablo Isaza Relatório

0

i think you are trying this on developer console. if you run this code as a file, you even doesn't get any output.

The developer console typically logs out the output from the codeblock. once the execution is done.

use console.log() in order to see all outputs.


console.log(add(1,2));
console.log(add(7,9));
console.log(add(3,5));

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