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

452
Views
How to catch the error of Private field must be declared in an enclosing class?

I have this sample code:

class Person {
  #name = "Jack";
  static hasTitle(obj) {
    try {
      console.log(obj.#age);
    } catch (error) {
      console.log(Object.keys(error));
    }

    return #name in obj;
  }
}

const p = new Person();
console.log(Person.hasTitle(p));

And I want to catch the error that occurs because age is not defined on the Person object. What happens now is that the catch block is never reached, despite wrapping the faulty line with a try/catch block. So what is the problem here?

I'm perfectly aware of the in operator in case you're wondering.

about 4 years ago · Juan Pablo Isaza
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!