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

66
Views
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
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!