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

291
Views
How are undefined, false, and null working here?

I have tried the following JavaScript code:

> var {a} = undefined;
Thrown:
TypeError: Cannot destructure property `a` of 'undefined' or 'null'.
> var {a} = false;
undefined

Essentially, can someone explain this error to me? Why does it occur, and how does {a} get set as undefined in the second line?

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

0

In the first example you try to access field a of undefined, which leads to error. You can try to access undefined fields manually:

console.log(undefined.a);

It will lead to:

Uncaught TypeError: Cannot read property 'a' of undefined

In the second example you access a field of false, but false doesn't have a field, that's why it is undefined. You can test it manually to:

console.log(false.a);
// undefined

If you want to avoid undefined values ​​after destructuring you can assign a default value:

let { a = "default value" } = false;
console.log(a);
// default value
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!