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

158
Views
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 answers
Answer question

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 Report

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