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

177
Views
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
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!