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

233
Views
Why doesn't the constructor property show up in for/in loop or Object.keys but works with getOwnPropertyNames?

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);
}
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!