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

68
Vistas
Behaviour of constructor function return

Can someone explain this behavior or phenomenon, and what exactly is happening behind the scene?

A constructor function initialized with a new keyword is supposed to return the current object context(this) implicitly.

function User() {
  this.name = "Alice";
}

console.log( new User() );

Which is working exactly what it says.

Also explicitly returning an object is also possible with

function User() {
  this.name = "Alice";

  return { name: "Jane" };
}

console.log( new User() );

Which explicitly returning object, but when trying to return primitive value it returns what is implicitly supposed to return.

function User() {
  this.name = "Alice";

  return "Jane";
}

console.log( new User() );

Thank you in advance. Your efforts will be great input to my knowledge. 

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