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

92
Views
Destructuring undefined inside an object vs array

Following code gives empty object {}:

{ 2, {...undefined}}

But why does below code gives error: Uncaught TypeError: undefined is not iterable?

{ 2, [...undefined]}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You cannot destructure an array if it's not an array for sure. It's ok to have an empty array so the given value will be undefined.

You can use this to prevent access undefined OR non-iterable value:

const a = undefined
console.log(...(a ?? []))

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!