What are the exact circumstances for which a return statement in Javascript can return a value other than this when a constructor is invoked using
Trying to put a few points in simpler words.
In javascript, when you use a new keyword on a function and if,
function User() {
this.name = 'Virat'
}
var user = new User();
console.log(user.name); //=> 'Virat'
user variable will hold the returned complex objectfunction User() {
this.name = 'Virat';
return function(){};
}
var user = new User();
console.log(user.name); //=> undefined
console.log(user); //=> function
function User() {
this.name = 'Virat';
return 10;
}
var user = new User();
console.log(user.name); //=> 'Virat'