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

169
Views
Function returning undefined, I know it's to do with the non-return but I am struggling to solve

I have a function that takes a variable called (compactArray) (there is another function to produce and return a compact array that works fine)

I know it's because my function is not returning any value, but I am struggling to solve the return = undefined.

the code is below

let a = null;
let b = null;
let operand = null;
let total = null;



function testGrab (compactArray) {
    if(compactArray == typeof(Number) && a == null) {
     return a = compactArray;
    } else if (compactArray == typeof(Number) && a !== null){
        return b = compactArray;
    } else if (compactArray == typeof(String)){
        return operand = compactArray; 
    }
  return total
};


const compactArray = 467; 

console.log(testGrab(compactArray));
console.log(a)

I want this function to take the compactArray returned from a different function and assign it to the correct variable a,b,operand.

is this possible, or would I need to make a function to return the relevant if statement, and then create another function to assign the returned value to the correct variable?

I know it's because my function is not returning anything but I am stumped at the moment.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

if you want to check whether compactArray's type is a number:

change this statement "if(compactArray == typeof(Number) && a == null)"

to this statement "if("number" == typeof(compactArray) && a == null)"

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!