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

156
Vistas
Sending request if property does not exist while destructuring JS object

I have object with property which should be destructred. But if it has false value I want to fetch it from backend.

const { property = await someMethodThatSendsRequest() } = myObject;

But this is not working. The question is - Is this even possible ?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Just use a variable as a default value:

const defaultProperty = myObject.property || await someMethodSendsRequest();
const { property = defaultProperty } = myObject;
about 4 years ago · Juan Pablo Isaza Denunciar

0

In a matter of fact, yes. It is possible. However, your property needs to get accessed in order to get a result of someMethodThatSendsRequest() since default parameters are evaluated at call time. A simple Sandbox that proves it.

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