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

112
Views
Continuar la función si la función devuelta no regresa

Estoy tratando de reducir la complejidad ciclomática, pero esta es una consulta general. si la función b no devuelve nada, la función a debería continuar devolviendo 3

 function a() { return b(); return 3 } function b() { if (false) return 2 } alert(a())

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

0

Más manualmente, podría almacenar el resultado de b() en una variable, verificar la variable y return o continuar condicionalmente. Aunque en esta versión simplificada también puede confiar en el operador coalescente nulo al regresar.

Por ejemplo:

 function a() { return b() ?? 3; } function b() { if (false) return 2 } alert(a())

Esencialmente, la expresión se resuelve en el resultado de b() o, si ese resultado es null o undefined , se resuelve en 3 . Luego se devuelve el resultado de esa expresión general.

about 4 years ago · Juan Pablo Isaza Report

0

Eso funciona con mi prueba, " console.log not alert "

 function a() { let val = b() return val == null ? 3 : val; } function b() { if (false) return 2; return null; // If anytings doesnt return that function we returns null } alert(a());

Prueba de rendimiento para operador nulo o una línea estándar si https://jsbench.me/ool12lcckh

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!