Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda