So here’s the code:
function foo() {};
let obj = new foo();
console.log(Object.getOwnPropertyNames(obj)); // []
console.log(Object.getOwnPropertyNames(Object.getPrototypeOf(obj)));
// [ 'constructor' ]
We create and instance of foo on line 3. On line 5, we output the own properties of instance obj which outputs and empty array. On line 6, we output the properties on the prototype of instance obj which displays an array containing the constructor property.
However, when I try to check for the constructor property using Object.keys or for/in loop, it doesn’t show up. Why?
function foo() {};
let obj = new foo();
console.log(Object.keys(Object.getPrototypeOf(obj))); // []
for (let key in Object.getPrototypeOf(obj)) {
console.log(key);
}