Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda