Why does Object.defineProperty make a property invisible when logged?

60 Views Asked by At

I'm trying to understand why using Object.defineProperty makes a property not visible when the object is logged in the console.

For instance:

let foo = {};

Object.defineProperty(foo, "a", {
  get() { return "a"; }
});

Object.defineProperty(foo, "b", {
  get() { return "b"; },
  enumerable: true
});

console.log( foo ); // returns {}

I do understand that enumerable will affect the outcome of a for...in loop or the Object.keys() static method. But I don't get why console.log(foo) returns {}, regardless of the use of enumerable, and even if I start by declaring foo as let foo = { a: 'bar' };

Thanks!

0

There are 0 best solutions below