0

It seems from Object.getOwnPropertyNames vs Object.keys, that the main difference between Object.keys() and Object.getOwnPropertyNames() is that the former only returns some of the properties -- those that are enumerable. So I'm wondering for something like an Error object, why it's decided that the properties aren't enumerable. For example:

try {
    let field="XYZ";
    field.a.b.c;
} catch (error) {
    console.log('111', Object.getOwnPropertyNames(error));
    console.log('222', Object.keys(error));
}

Why for example does the Error object not make those properties enumerable? When is a property usually made enumerable?

samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
  • maybe this helps https://stackoverflow.com/questions/14984533/what-are-the-benefits-of-making-properties-non-enumerable – cmgchess Feb 10 '22 at 19:05
  • this might help [Developer.Mozilla.Org Enumerability and ownership of properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties) – Huzaifa Feb 10 '22 at 19:05

0 Answers0