Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

277
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!